summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-01-16 15:44:00 -0300
committerSebastian <sebasjm@gmail.com>2024-01-16 15:44:00 -0300
commit54d5cb4584e8c0378fe09ee4c9b8e7760ff293af (patch)
tree18024933f2a2b55583fb1fcb2b0abb34a7271bd8
parent1c286ebb2f1c817f5362517d47466c39826c8699 (diff)
downloadwallet-core-54d5cb4584e8c0378fe09ee4c9b8e7760ff293af.tar.gz
wallet-core-54d5cb4584e8c0378fe09ee4c9b8e7760ff293af.tar.bz2
wallet-core-54d5cb4584e8c0378fe09ee4c9b8e7760ff293af.zip
fix new node version
-rwxr-xr-xpackages/web-util/build.mjs45
1 files changed, 45 insertions, 0 deletions
diff --git a/packages/web-util/build.mjs b/packages/web-util/build.mjs
index c15a2715b..6320b4937 100755
--- a/packages/web-util/build.mjs
+++ b/packages/web-util/build.mjs
@@ -50,6 +50,49 @@ function git_hash() {
}
}
+/**
+ * Problem:
+ * No loader is configured for ".node" files: ../../node_modules/.pnpm/fsevents@2.3.3/node_modules/fsevents/fsevents.node
+ *
+ * Reference:
+ * https://github.com/evanw/esbuild/issues/1051#issuecomment-806325487
+ */
+const nativeNodeModulesPlugin = {
+ name: 'native-node-modules',
+ setup(build) {
+ // If a ".node" file is imported within a module in the "file" namespace, resolve
+ // it to an absolute path and put it into the "node-file" virtual namespace.
+ build.onResolve({ filter: /\.node$/, namespace: 'file' }, args => ({
+ path: require.resolve(args.path, { paths: [args.resolveDir] }),
+ namespace: 'node-file',
+ }))
+
+ // Files in the "node-file" virtual namespace call "require()" on the
+ // path from esbuild of the ".node" file in the output directory.
+ build.onLoad({ filter: /.*/, namespace: 'node-file' }, args => ({
+ contents: `
+ import path from ${JSON.stringify(args.path)}
+ try { module.exports = require(path) }
+ catch {}
+ `,
+ }))
+
+ // If a ".node" file is imported within a module in the "node-file" namespace, put
+ // it in the "file" namespace where esbuild's default loading behavior will handle
+ // it. It is already an absolute path since we resolved it to one above.
+ build.onResolve({ filter: /\.node$/, namespace: 'node-file' }, args => ({
+ path: args.path,
+ namespace: 'file',
+ }))
+
+ // Tell esbuild's default loading behavior to use the "file" loader for
+ // these ".node" files.
+ let opts = build.initialOptions
+ opts.loader = opts.loader || {}
+ opts.loader['.node'] = 'file'
+ },
+}
+
const buildConfigBase = {
outdir: "lib",
bundle: true,
@@ -66,6 +109,7 @@ const buildConfigBase = {
__VERSION__: `"${_package.version}"`,
__GIT_HASH__: `"${GIT_HASH}"`,
},
+ plugins: [nativeNodeModulesPlugin],
};
/**
@@ -122,6 +166,7 @@ const buildConfigNode = {
format: "cjs",
platform: "node",
external: ["preact"],
+
};
/**