hqjs / hq

Lightning fast, zero configuration, web application development server
https://hqjs.org
MIT License
126 stars 11 forks source link

Builds broken on windows #25

Closed Zageron closed 3 years ago

Zageron commented 4 years ago

Likely the same path issue as before. Luckily ubuntu builds still work so I can just build over there. :)

Ubuntu

❯ npm -g list --depth=0
/home/zageron/.nvm/versions/node/v12.18.4/lib
├── @hqjs/hq@0.0.26
├── npm@6.14.8
├── npm-check-updates@9.0.2
└── typescript@4.0.3
❯ hq build
(c) hqjs @ 0.0.26
Start time: 0.2 s

Visit https://localhost:8080
or https://172.31.211.4:8080 within local network

⬇️  /index.html

🆗 /index.html

⬇️  /stylesheets/style.scss

⬇️  /index.ts

🆗 /index.ts

⬇️  /render

🆗 /stylesheets/style.scss

🆗 /render

⬇️  /index.html

🆗 /index.html

⬇️  /index.ts

🆗 /index.ts

⬇️  /render

🆗 /render

📦 Bundling for old browsers

✅ Build successfully completed!

Windows

L:\git\zageron\tinkering>npm -g list --depth=0
C:\Users\Zageron\AppData\Roaming\npm
+-- @hqjs/hq@0.0.26
+-- npm@6.14.8
+-- npm-check-updates@9.0.2
+-- sass@1.26.11
`-- typescript@4.0.3
L:\git\zageron\tinkering>hq build
(c) hqjs @ 0.0.26
Start time: 0.2 s

Visit http://localhost:8080
or http://192.168.1.239:8080 within local network

⬇️  /index.html

� /index.html

⬇️  /L:\stylesheets\style.scss

⬇️  /L:\index.ts

❌ Error /L:/index.ts: File /L:/index.ts not found

NotFoundError: File /L:/index.ts not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:37:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5

❌ Error /L:/stylesheets/style.scss: File /L:/stylesheets/style.scss not found

NotFoundError: File /L:/stylesheets/style.scss not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:37:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5

Error: Unable to build /L:\index.ts: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:162:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

Error: Unable to build /L:\stylesheets\style.scss: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:162:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

⬇️  /index.html

� /index.html

⬇️  /L:\index.ts

❌ Error /L:/index.ts: File /L:/index.ts not found

NotFoundError: File /L:/index.ts not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:37:5
    at async cors (C:\Users\Zageron\AppData\Roaming\npm\node_modules\@hqjs\hq\node_modules\@koa\cors\index.js:56:32)
    at async file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/middlewares/error-handler.mjs:5:5

Error: Unable to build /L:\index.ts: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:162:22)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/npm/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

� Bundling for old browsers

⚠️  Build completed with errors:
    � Error: Unable to build /L:\index.ts: Not Found
    � Error: Unable to build /L:\stylesheets\style.scss: Not Found
    � Error: Unable to build /L:\index.ts: Not Found
hqjs commented 4 years ago

@Zageron can you please try hq --verbose build it seems like for windows it can't determine project root in build mode. I still have no windows machine and can't properly debug it. Will appreciate your help.

Wrong assumption. For some reasons request path contains disk letter L:\ in your case. Not sure how it gets there. @Zageron will you be able to debug crawl/index.mjs and watch queue variable?

Just in case - check the raw output of index.html in dist folder if it contains disk letter L:\ there - the problem is dipper.

hqjs commented 4 years ago

@Zageron I tried to hack it, please try hq@0.0.27

Zageron commented 4 years ago

If you would be able to write up a quick set of dev instructions on how you have hq set up for debugging, I'd certainly be able to try debugging for future issues as well. Do you do much beyond having the project linked as a local dependency? I only have limited experience debugging my own dependencies, so some instructions would be appreciated, if possible.

I'll give that version a try a little later today, thanks for your attempt! :D

hqjs commented 4 years ago
Screenshot 2020-11-07 at 20 47 28

Thanks! If you have vscode - there is a launch.json that allow to run hq and serve hq or build hq. You can change launch config to serve your project instead and put breakpoints on right in the code. Or you can do npm link and just debug with good old console.log.

I've found an error in my workaround and publish hq@0.0.28

Zageron commented 4 years ago

Here's my build output. I'll look at debugging in a bit.

Verbose flag seems to be broken now.

PS L:\git\zageron\tinkering> hq build
(c) hqjs @ 0.0.28
Start time: 0.6 s

Visit http://localhost:8080
or http://172.28.64.1:8080 within local network

⬇️  /index.html

� /index.html

⬇️  /L:/git/zageron/tinkering/stylesheets/style.scss

⬇️  /L:/git/zageron/tinkering/index.ts

❌ Error /L:/git/zageron/tinkering/stylesheets/style.scss: File /L:/git/zageron/tinkering/stylesheets/style.scss not found

NotFoundError: File /L:/git/zageron/tinkering/stylesheets/style.scss not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\nvm\v12.18.4\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)

❌ Error /L:/git/zageron/tinkering/index.ts: File /L:/git/zageron/tinkering/index.ts not found

NotFoundError: File /L:/git/zageron/tinkering/index.ts not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\nvm\v12.18.4\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)

Error: Unable to build /L:/git/zageron/tinkering/stylesheets/style.scss: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:163:22)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

Error: Unable to build /L:/git/zageron/tinkering/index.ts: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:163:22)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

⬇️  /index.html

� /index.html

⬇️  /L:/git/zageron/tinkering/index.ts

❌ Error /L:/git/zageron/tinkering/index.ts: File /L:/git/zageron/tinkering/index.ts not found

NotFoundError: File /L:/git/zageron/tinkering/index.ts not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\nvm\v12.18.4\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)

Error: Unable to build /L:/git/zageron/tinkering/index.ts: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:163:22)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:115:5)

� Bundling for old browsers

⚠️  Build completed with errors:
    � Error: Unable to build /L:/git/zageron/tinkering/stylesheets/style.scss: Not Found
    � Error: Unable to build /L:/git/zageron/tinkering/index.ts: Not Found
    � Error: Unable to build /L:/git/zageron/tinkering/index.ts: Not Found

PS L:\git\zageron\tinkering>

Extra verbose bit

PS L:\git\zageron\tinkering> hq --verbose build
(c) hqjs @ 0.0.28
Start time: 0.5 s

Visit http://localhost:8080
or http://172.28.64.1:8080 within local network

| hq root    : C:\Users\Zageron\AppData\Roaming\nvm\v12.18.4\node_modules\@hqjs\hq

| root       : L:\git\zageron\tinkering
| src        : src

| certs      :

| babelrc    : undefined
| postcssrc  : undefined
| posthtmlrc : undefined

⬇️  /--verbose

�  USER AGENT hq 1.0 for module

❌ Error /--verbose: File /--verbose not found

NotFoundError: File /--verbose not found
    at Object.throw (C:\Users\Zageron\AppData\Roaming\nvm\v12.18.4\node_modules\@hqjs\hq\node_modules\koa\lib\context.js:97:11)
    at resolveSrc (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/middlewares/resolve-path.mjs:128:21)

Error: Unable to build /--verbose: Not Found
    at build (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:163:22)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async request (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:115:5)
    at async makeBuild (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:63:3)
    at async default (file:///C:/Users/Zageron/AppData/Roaming/nvm/v12.18.4/node_modules/@hqjs/hq/crawl/index.mjs:38:3)
hqjs commented 4 years ago

Right, verbose won't work with build, it treats it as an argument for build. I have to fix it.

That is super strange that full path is in request path /L:/git/zageron/tinkering/index.ts. I'll appreciate help with debugging.

Zageron commented 4 years ago

How do I specify a different project from launch?

hqjs commented 4 years ago

You should specify cwd which is absolute path to your project in launch configuration.

hqjs commented 4 years ago

For example

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch HQ",
      "program": "${workspaceFolder}/index.mjs",
      "runtimeArgs": [
        "--experimental-modules",
        "--experimental-json-modules"
      ]
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Launch HQ Build",
      "program": "${workspaceFolder}/index.mjs",
      "runtimeArgs": [
        "--experimental-modules",
        "--experimental-json-modules"
      ],
      "args": [
        "build"
      ],
      "cwd": "/Users/yuri/web/hqjs.github.io"
    }
  ]
}
Zageron commented 4 years ago

Seems to be a problem with: export const pathToURL = filePath => url.pathToFileURL(filePath).href.slice('file:///'.length).replace(/^[a-zA-Z]:/, '');

// Trying 3 slashes
        const tempPath0 = urlModule.pathToFileURL(rpath); 
        const tempPath1 = tempPath0.href; // 'file:///L:/git/zageron/tinkering/stylesheets/style.scss'
        const tempPath2 = tempPath1.slice('file:///'.length); // 'L:/git/zageron/tinkering/stylesheets/style.scss'
        const tempPath3 = tempPath2.replace(/^[a-zA-Z]:/, ''); // '/git/zageron/tinkering/stylesheets/style.scss'
// Result with 2 slashes
        const tempPath0 = urlModule.pathToFileURL(rpath); 
        const tempPath1 = tempPath0.href; // 'file:///L:/git/zageron/tinkering/stylesheets/style.scss'
        const tempPath2 = tempPath1.slice('file://'.length); // '/L:/git/zageron/tinkering/stylesheets/style.scss'
        const tempPath3 = tempPath2.replace(/^[a-zA-Z]:/, ''); // '/L:/git/zageron/tinkering/stylesheets/style.scss'
hqjs commented 4 years ago

@Zageron pathToURL works in other places. Do you understand why disk letter appears in link paths? queue suppose to have all links collected from html, js and css and I have no idea why disk letter appears there. I added pathToURL to line 123 of crawl/index.mjs as a hack, but I don't understand how filesystem path gets there? Can you please check how queue variable changes after index.html parsing? May be put some breakpoints to crawl/index.mjs and crawl/html.mjs.

Zageron commented 4 years ago

This is what I get on linux: rpath and fpath are both relative paths: 'stylesheets/style.scss' Using the pathToFileUrl function I get this: 'file:///mnt/l/git/zageron/tinkering/stylesheets/style.scss'

When it finishes it returns: tfPath = '/stylesheets/style.css' trPath = '/mnt/l/git/zageron/tinkering/stylesheets/style.scss'

The queue stuff in htlm.mjs is always the relative path from what I can see. ex. '/stylesheets/style.css'

Windows would always return the drive letter because link paths in windows always include the drive letter. (For example this is a functioning link in windows: file:///C:\Users\Zageron\.vscode\extensions\jacqueslucke.blender-development-0.0.12

Zageron commented 4 years ago

Here's a bit of experimentation:

    await Promise.allSettled(Array.from(queue.entries())
      .map(([ fpath, rpath ]) => {
        const tempPath0 = urlModule.pathToFileURL(rpath);
        const tempPath1 = tempPath0.href;
        const tempPath2 = tempPath1.slice('file://'.length);
        const uPath = tempPath1.slice('file:///'.length);
        const tempPath3 = tempPath2.replace(/^[a-zA-Z]:/, '');
        //const uPath = pathToURL(rpath);
        const trPath = uPath.startsWith(baseURI) ?
          uPath.slice(baseURI.length) :
          !uPath.startsWith('/') ?
            path.resolve('/', uPath) :
            uPath;
        const tfPath = fpath.startsWith(baseURI) ?
          fpath.slice(baseURI.length) :
          !fpath.startsWith('/') ?
            path.resolve('/', fpath) :
            fpath;
        return [ tfPath, trPath ];
      })

The result of trPath is correct with this: 'L:\\git\\zageron\\tinkering\\stylesheets\\style.scss' But the tfPath is resolving incorrectly: 'L:\\stylesheets\\style.css'

This is definitely an assumption of similar behaviour between linux and windows. Where / is the root of a link in linux, but the drive letter is the root of a link in windows. Not entirely sure how to resolve this, the variable names in this code block aren't descriptive enough for me to understand what they're supposed to be, so.

Hope this helps.

hqjs commented 4 years ago

Thanks! I will remove urlToPath - it was bad idea. How drive letter get into a path? It is the link from index.html so it should be either relative or absolute from the project root, but not from system root. Can you please check what is the output for index.html if you remove urlToPath?

hqjs commented 4 years ago

fPath represents file path while rPath - should be request path.

hqjs commented 4 years ago

Does queue in index.html on Windows also includes /stylesheets/style.css? Or it has drive letter?

Zageron commented 4 years ago

iirc it had no drive letter in queue. Drive letter was only added after calling uriToPath, and/or resolve function.

hqjs commented 4 years ago

In your original post there was no pathToURL present, but there was still a drive letter. Can you please remove pathToURL or just update to latest and check where this letter appears? It not suppose to be there and that is what cause the problem.

Zageron commented 4 years ago

It's coming from the path.resolve('/', rpath) calls.

hqjs commented 4 years ago

Thanks! That helps a lot! I'll prepare a fix during next week and let you know.

hqjs commented 3 years ago

@Zageron I pushed an update to master without release. Can you please test if it fixes the problem with windows build?

hqjs commented 3 years ago

Actually published it as hq@0.0.30

hqjs commented 3 years ago

Closed due to inactivity, should be fixed by now

Zageron commented 3 years ago

Thank you apologies for inactivity I've been over in rust land, as well as working and holidaying.

Thanks for resolving this for me!

hqjs commented 3 years ago

No worries, hope it is working, if not feel free to reopen an issue or create a new one. Merry Christmas and happy new year!