Skip to content

Conversation

@yjoer
Copy link
Contributor

@yjoer yjoer commented Jul 1, 2025

Now that the dust has settled, I'm repurposing this PR to focus on simplifying the build process by removing the dependency on ncc and replacing it with a direct webpack build. This change helps resolve the cyclic dependency and avoids some of the quirks associated with ncc. The tradeoff is that we now need to maintain a small custom webpack configuration, and there's a risk that certain edge cases previously handled by ncc may not be fully covered.

Building the loader with webpack passes the same set of tests as the build script. This brings us to a decision point: either continue using ncc or move forward without it. This, perhaps, provides a fallback in case ncc introduces issues again.


I'm working on fixing the tests for #193. While running them, the only intermittent failure I encountered was in project.test.js, where the number of lines in the webpack output is being asserted. After running the tests multiple times, I observed that the output fluctuates between 16 and 17 lines. To address this, we could update the test to allow either value.

16 lines:

[
  'assets by path \x1B[1m\x1B[32mmodules/\x1B[39m\x1B[22m 1.15 KiB',
  '  asset \x1B[1m\x1B[32mmodules/main.js\x1B[39m\x1B[22m 729 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m (name: main)',
  '  asset \x1B[1m\x1B[32mmodules/chunk.js\x1B[39m\x1B[22m 317 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m (name: chunk)',
  '  asset \x1B[1m\x1B[32mmodules/chunks/758.js\x1B[39m\x1B[22m 127 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m',
  'assets by path \x1B[1m\x1B[32m*.txt\x1B[39m\x1B[22m 19 bytes',
  '  asset \x1B[1m\x1B[32masset.txt\x1B[39m\x1B[22m 7 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m (auxiliary name: main)',
  '  asset \x1B[1m\x1B[32masset1.txt\x1B[39m\x1B[22m 7 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m (auxiliary name: chunk)',
  '  asset \x1B[1m\x1B[32masset3.txt\x1B[39m\x1B[22m 5 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m',
  'runtime modules 1.67 KiB 6 modules',
  'built modules 456 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m',
  '  \x1B[1m./main.js\x1B[39m\x1B[22m 176 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1m./chunk.js\x1B[39m\x1B[22m 133 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1mexternal "fs"\x1B[39m\x1B[22m 42 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1m./chunk2.js\x1B[39m\x1B[22m 105 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  'webpack 5.76.0 compiled \x1B[1m\x1B[32msuccessfully\x1B[39m\x1B[22m in 416 ms',
  ''
]

17 lines:

[
  'assets by status 1.04 KiB \x1B[1m\x1B[32m[emitted]\x1B[39m\x1B[22m',
  '  assets by path \x1B[1m\x1B[32mmodules/*.js\x1B[39m\x1B[22m 1.02 KiB',
  '    asset \x1B[1m\x1B[32mmodules/main.js\x1B[39m\x1B[22m 730 bytes \x1B[1m\x1B[32m[emitted]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m (name: main)',
  '    asset \x1B[1m\x1B[32mmodules/chunk.js\x1B[39m\x1B[22m 316 bytes \x1B[1m\x1B[32m[emitted]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m (name: chunk)',
  '  assets by status 14 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m',
  '    asset \x1B[1m\x1B[32masset.txt\x1B[39m\x1B[22m 7 bytes \x1B[1m\x1B[32m[emitted]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m (auxiliary name: chunk)',
  '    asset \x1B[1m\x1B[32masset1.txt\x1B[39m\x1B[22m 7 bytes \x1B[1m\x1B[32m[emitted]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m (auxiliary name: main)',
  'asset \x1B[1m\x1B[32mmodules/chunks/758.js\x1B[39m\x1B[22m 127 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m \x1B[1m\x1B[32m[minimized]\x1B[39m\x1B[22m',
  'asset \x1B[1m\x1B[32masset3.txt\x1B[39m\x1B[22m 5 bytes \x1B[1m\x1B[33m[compared for emit]\x1B[39m\x1B[22m',
  'runtime modules 1.67 KiB 6 modules',
  'built modules 456 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m',
  '  \x1B[1m./main.js\x1B[39m\x1B[22m 177 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1m./chunk.js\x1B[39m\x1B[22m 132 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1mexternal "fs"\x1B[39m\x1B[22m 42 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  '  \x1B[1m./chunk2.js\x1B[39m\x1B[22m 105 bytes \x1B[1m\x1B[33m[built]\x1B[39m\x1B[22m \x1B[1m\x1B[33m[code generated]\x1B[39m\x1B[22m',
  'webpack 5.76.0 compiled \x1B[1m\x1B[32msuccessfully\x1B[39m\x1B[22m in 428 ms',
  ''
]

@yjoer yjoer requested review from Timer and styfle as code owners July 1, 2025 16:57
@yjoer yjoer changed the title fix a test for fix: 1.7.3 to 1.7.4 regression fix: a test for fix: 1.7.3 to 1.7.4 regression Jul 1, 2025
@yjoer yjoer changed the title fix: a test for fix: 1.7.3 to 1.7.4 regression fix: support node:path and fix 1.7.3 to 1.7.4 regression Jul 2, 2025
@yjoer yjoer force-pushed the patch-1 branch 2 times, most recently from 9cbcad2 to ff83ab9 Compare July 2, 2025 18:23
styfle pushed a commit that referenced this pull request Jul 3, 2025
Extracted from #194

I aliased `node:path` to `path` within the `staticModules` object so
that any encounters of `node:path` would have the same behavior as
`path`.

I have added unit tests specifically for `path` and `node:path`.
Additionally, I've included a new chunk in the integration test to
ensure asset references work correctly when using `resolve` or
`path.resolve` imported from `node:path`.

- Fixes: #191
styfle added a commit that referenced this pull request Jul 4, 2025
…#198)

Extracted from #194

This is taking advantage of #185, which used a function in
node-gyp-build to compute the path. Some moons ago,
[node-gyp-build.js#L62-L75](https://github.com/prebuild/node-gyp-build/blob/v4.8.4/node-gyp-build.js#L62-L75)
was updated with a function to resolve native addons from the prebuilds
directory. All we have to do here is update `node-gyp-build`.

This enables assets relocation for packages like [bcrypt
v6.0.0](https://www.npmjs.com/package/bcrypt?activeTab=code)

I added some tests according to the platform used in CI. Hopefully, the
architecture and the fixtures align well.

---------

Co-authored-by: Steven <[email protected]>
@yjoer yjoer changed the title fix: support node:path and fix 1.7.3 to 1.7.4 regression build: explore the feasibility of dropping ncc in favor of building with webpack directly Jul 4, 2025
Copy link
Member

@styfle styfle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also update gh actions workflow to run the tests, right?

@yjoer
Copy link
Contributor Author

yjoer commented Jul 8, 2025

Uh, yes. The conservative way is to test this in addition to existing tests based on ncc builds. If it doesn't introduce issues when making other changes for some time, we can promote this as the primary way. What do you think?

@styfle
Copy link
Member

styfle commented Jul 9, 2025

I'm also wondering if we need to bundle this at all. Since its a plugin, it seems strange that we bundle before publishing to npm. Usually thats for CLIs or frontend code, but not a plugin like this.

@yjoer
Copy link
Contributor Author

yjoer commented Jul 9, 2025

The benefit of bundling is that it eliminates the need to install dependencies and numerous of their descendants, which are now listed under dev dependencies. The tradeoff, however, is that it makes the package harder to read and inspect. Back at it again, trying to choose between two paths 😵

@yjoer
Copy link
Contributor Author

yjoer commented Jul 10, 2025

I moved the runtime dependencies into a temporary file package.json and visualized the dependency graph. It appears that node-pre-gyp is the only package responsible for introducing a large number of transitive dependencies.

1

@styfle
Copy link
Member

styfle commented Jul 10, 2025

We could swap it for the @mapbox/node-pre-gyp like we did with @vercel/nft

vercel/nft#199

@github-actions
Copy link

🎉 This issue has been resolved in version 1.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

yjoer added a commit to yjoer/webpack-asset-relocator-loader that referenced this pull request Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants