Skip to content

Commit be71be5

Browse files
fix(esbuild): avoid usingcreateRequire as import name
1 parent 2f4d29b commit be71be5

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/bundler/ESBuildBundler.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export default class ESBuildBundler extends BaseBundler {
6161
],
6262
banner: {
6363
js: [
64-
'import { createRequire } from "module";',
65-
'const require = createRequire(import.meta.url);',
64+
'import { createRequire as hedyCreateRequire } from "module";',
65+
'const require = hedyCreateRequire(import.meta.url);',
6666
'',
6767
].join('\n'),
6868
},
@@ -74,10 +74,17 @@ export default class ESBuildBundler extends BaseBundler {
7474
name: 'alias-main',
7575
setup: (build) => {
7676
build.onResolve({ filter: /^\.\/main\.js$/ }, () => ({ path: cfg.file }));
77-
// use @adobe/helix-universal in the calling service, not ours
7877
build.onResolve(
7978
{ filter: /^@adobe\/helix-universal$/ },
80-
(args) => ({ path: path.resolve(cfg.cwd, 'node_modules', args.path, 'src', 'index.js') }),
79+
(args) => {
80+
const cwd = (process.env.HELIX_FETCH_FORCE_HTTP1 === 'true')
81+
// for testing use "our" @adobe/helix-universal dependency
82+
? path.resolve(__dirname, '..', '..')
83+
// for production use @adobe/helix-universal (and its dependencies)
84+
// in the calling service
85+
: cfg.cwd;
86+
return { path: path.resolve(cwd, 'node_modules', args.path, 'src', 'index.js') };
87+
},
8188
);
8289
cfg.externals.forEach((filter) => {
8390
build.onResolve({ filter }, (args) => ({ path: args.path, external: true }));

src/template/node-index.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export default {
2222
openwhisk,
2323
lambda,
2424
google,
25-
}
25+
};

test/build.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,12 @@ describe('Build Test', () => {
167167
it('generates the bundle (esm, webpack) fails', async () => {
168168
await assert.rejects(generate(['--esm']), Error('Webpack bundler does not support ESM builds.'));
169169
}).timeout(5000);
170+
171+
it('generates the bundle (esm, esbuild)', async () => {
172+
await generate(['--bundler=esbuild', '--esm'], PROJECT_SIMPLE_ESM);
173+
});
174+
175+
it('generates the bundle (esbuild) fails', async () => {
176+
await assert.rejects(generate(['--bundler=esbuild']), Error('ESBuild bundler only supports ESM builds.'));
177+
});
170178
});

test/setup-env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
* OF ANY KIND, either express or implied. See the License for the specific language
1010
* governing permissions and limitations under the License.
1111
*/
12-
// eslint-disable-next-line no-console
1312
import path from 'path';
1413
import { fileURLToPath } from 'url';
1514

15+
// eslint-disable-next-line no-console
1616
console.log('Forcing HTTP/1.1 for @adobe/fetch');
1717
process.env.HELIX_FETCH_FORCE_HTTP1 = 'true';
1818

0 commit comments

Comments
 (0)