Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jaymcp opened this issue Jul 24, 2023 · 5 comments · Fixed by #99
Closed

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

jaymcp opened this issue Jul 24, 2023 · 5 comments · Fixed by #99
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jaymcp
Copy link
Member

jaymcp commented Jul 24, 2023

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.
@jaymcp jaymcp added the bug Something isn't working label Jul 24, 2023
@ampersarnie
Copy link
Member

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

@jaymcp
Copy link
Member Author

jaymcp commented Jul 24, 2023

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

@ampersarnie ampersarnie changed the title [Bug]: Production build assumes existence of generated file Production build assumes existence of generated file Jul 24, 2023
@ampersarnie
Copy link
Member

ampersarnie commented Jul 24, 2023

@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
Copy link
Member Author

jaymcp commented Jul 24, 2023

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
Copy link
Member

@jonmcp Yeah that would be great thank you.

@jaymcp jaymcp changed the title Production build assumes existence of generated file Production build assumes existence of inc/ directory within project root Jul 24, 2023
@ampersarnie ampersarnie added this to the Hotfix milestone Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants