Skip to content

Commit 5731df3

Browse files
committed
chore: load .node prebuild files with prescribed webpack method
remove `node-loader` package https://github.com/webpack/webpack/tree/main/examples/nodejs-addons `tree-sitter` is no longer an external for the server module
1 parent a1d635e commit 5731df3

File tree

3 files changed

+23
-76
lines changed

3 files changed

+23
-76
lines changed

package-lock.json

Lines changed: 0 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"jest": "^29.7.0",
121121
"jest-environment-jsdom": "28.1.1",
122122
"js-yaml": "^4.1.0",
123-
"node-loader": "^2.1.0",
124123
"nx": "19.1.1",
125124
"nx-cloud": "19.0.0",
126125
"prebuildify": "^6.0.1",

packages/server/webpack.config.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,34 @@ module.exports = composePlugins(withNx(), withWeb(), (config) => {
4747
},
4848
{
4949
test: /\.node$/,
50-
loader: 'node-loader',
50+
type: 'asset/resource',
51+
generator: {
52+
// Ensure that prebuilt `.node` files are placed in the correct relative path for `node-gyp-build` to find them
53+
// "Prebuilds will be attempted loaded from `MODULE_PATH/prebuilds/...`"
54+
filename: (/** @type {import('webpack').PathData} */ pathData) => {
55+
if (!pathData.filename) {
56+
return 'prebuilds/[name].[hash][ext]';
57+
}
58+
59+
const parts = pathData.filename.split('/');
60+
61+
const prebuildsIndex = parts.indexOf('prebuilds');
62+
63+
if (prebuildsIndex === -1) {
64+
return 'prebuilds/[name].[hash][ext]';
65+
}
66+
67+
const prebuildDir = parts.slice(prebuildsIndex, -1).join('/');
68+
const assetModulePath = `${prebuildDir}/[name].[hash][ext]`;
69+
70+
return assetModulePath;
71+
},
72+
},
5173
},
5274
],
5375
};
5476
config.externals = {
5577
vscode: 'commonjs vscode', // ignored because it doesn't exist
56-
'tree-sitter': 'commonjs tree-sitter',
57-
'@keqingmoe/tree-sitter': 'commonjs @keqingmoe/tree-sitter',
5878
'tree-sitter-ccini': 'commonjs ../../tree-sitter-ccini',
5979
};
6080

0 commit comments

Comments
 (0)