bigbite / build-tools

MIT License
6 stars 1 forks source link

Production build assumes existence of `inc/` directory within project root #92

Closed jaymcp closed 10 months ago

jaymcp commented 1 year ago

What happened?

When running a build, Build Tools assumes the existence of an inc/ directory in the project root. If the directory doesn't exist, a raw error is thrown by Node.js as Build Tools attempts to write to the file inc/asset-settings.php.

Ideally, Build Tools would attempt create the directory (if it doesn't exist); alternatively, a more user-friendly error message could be thrown.

The command I am running to reproduce this is

build-tools build --production --once

My directory structure looks like the following:

project/
  - dist/
  - src/
  - package.json
  - webpack.config.js
  - yarn.lock

Which environments are you experiencing the issue on?

CLI (macOS, Windows, etc)

Relevant log output

yarn run v1.22.19
warning package.json: No license field
$ build-tools build --production --once
Compiling single project in production mode.
Processing the following projects:
 *  [sample-project/package.json]

⠼ Compiling...Error: ENOENT: no such file or directory, open '/Users/jon/Code/temp/sample-project/inc/asset-settings.php'
    at Object.openSync (node:fs:601:3)
    at Object.writeFileSync (node:fs:2249:35)
    at /Users/jon/Code/temp/sample-project/node_modules/@bigbite/build-tools/src/commands/build/plugins/custom/template-generator/index.js:28:12
    at Array.forEach (<anonymous>)
    at TemplateGenerator.createTemplates (/Users/jon/Code/temp/sample-project/node_modules/@bigbite/build-tools/src/commands/build/plugins/custom/template-generator/index.js:18:20)
    at Hook.eval [as callAsync] (eval at create (/Users/jon/Code/temp/sample-project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/jon/Code/temp/sample-project/node_modules/tapable/lib/Hook.js:18:14)
    at /Users/jon/Code/temp/sample-project/node_modules/webpack/lib/Compiler.js:882:27
    at /Users/jon/Code/temp/sample-project/node_modules/neo-async/async.js:2818:7
    at done (/Users/jon/Code/temp/sample-project/node_modules/neo-async/async.js:3522:9)
    at Hook.eval [as callAsync] (eval at create (/Users/jon/Code/temp/sample-project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
    at /Users/jon/Code/temp/sample-project/node_modules/webpack/lib/Compiler.js:736:33
    at /Users/jon/Code/temp/sample-project/node_modules/graceful-fs/graceful-fs.js:143:16
    at /Users/jon/Code/temp/sample-project/node_modules/graceful-fs/graceful-fs.js:61:14
    at FSReqCallback.oncomplete (node:fs:198:23) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/jon/Code/temp/sample-project/inc/asset-settings.php'
}
1 asset
chunk (runtime: frontend) frontend-ffc666a0.js (frontend) 208 KiB [entry] [rendered]
8 modules
webpack 5.88.2 compiled successfully in 1993 ms

✔ Build complete.
✨  Done in 3.01s.
ampersarnie commented 1 year ago

@jonmcp Which version of Build Tools are you running here?

jaymcp commented 1 year ago

I was actually running on #hotfix/handle-overwritten-externals, but experience the same output on v1.2.2

ampersarnie commented 1 year ago

@jonmcp I've done some testing and the problem isn't the missing asset-settings.php, it's a missing inc/ directory. If that directory exists, then the asset-settings.php file is created as expected.

I've found the following file and directory structures work as expected:

Working:

inc/
src/
 - entrypoints/
   - frontend.js

Working:

inc/
 - asset_settings.php
src/
 - entrypoints/
   - frontend.js

Failing:

src/
 - entrypoints/
   - frontend.js

Tested by using the example-site and removing the inc directories in test-client-plugin and test-plugin. The following command run:

cd example-site
node ../src/cli.js build --once test-client-plugin,test-plugin
jaymcp commented 1 year ago

Ah; thanks for that, and apologies for not attempting that during my testing prior to creating this issue. I can confirm that adding an empty inc directory resolves the error. Would you like me to update the issue title and description for clarity?

ampersarnie commented 1 year ago

@jonmcp Yeah that would be great thank you.