Skip to content

Commit 0db4650

Browse files
committed
fix(bundle): plugin helper
1 parent c92bf41 commit 0db4650

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

src/compiler/app-core/bundle-app-core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function bundleApp(config: d.Config, compilerCtx: d.CompilerCtx, bu
4545
...config.commonjs
4646
}),
4747
...config.rollupPlugins,
48-
pluginHelper(config, compilerCtx, buildCtx),
48+
pluginHelper(config, buildCtx),
4949
config.sys.rollup.plugins.nodeResolve({
5050
mainFields: ['collection:main', 'jsnext:main', 'es2017', 'es2015', 'module', 'main'],
5151
browser: true,

src/compiler/component-hydrate/bundle-hydrate-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function bundleHydrateApp(config: d.Config, compilerCtx: d.Compiler
3838
...config.commonjs
3939
}),
4040
...config.rollupPlugins,
41-
pluginHelper(config, compilerCtx, buildCtx),
41+
pluginHelper(config, buildCtx),
4242
config.sys.rollup.plugins.nodeResolve({
4343
mainFields: ['collection:main', 'jsnext:main', 'es2017', 'es2015', 'module', 'main'],
4444
...config.nodeResolve

src/compiler/rollup-plugins/plugin-helper.ts

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,29 @@ import * as d from '../../declarations';
22
import { buildError } from '@utils';
33

44

5-
export function pluginHelper(config: d.Config, compilerCtx: d.CompilerCtx, builtCtx: d.BuildCtx) {
5+
export function pluginHelper(config: d.Config, builtCtx: d.BuildCtx) {
66
return {
77
name: 'pluginHelper',
8+
resolveId(importee: string, importer: string): null {
9+
if (/\0/.test(importee)) {
10+
// ignore IDs with null character, these belong to other plugins
11+
return null;
12+
}
813

9-
async resolveId(importee: string, importer: string): Promise<string> {
10-
if (importee) {
11-
if (/\0/.test(importee)) {
12-
// ignore IDs with null character, these belong to other plugins
13-
return null;
14-
}
15-
if (importee.slice(-1) === '/') {
16-
importee === importee.slice(0, -1);
17-
}
18-
19-
if (builtIns.has(importee) || globals.has(importee)) {
20-
let fromMsg = '';
21-
if (importer) {
22-
if (importer.endsWith('.js')) {
23-
const tsxFile = importer.substr(0, importer.length - 2) + 'tsx';
24-
const tsxFileExists = await compilerCtx.fs.access(tsxFile);
25-
if (tsxFileExists) {
26-
importer = tsxFile;
27-
28-
} else {
29-
const tsFile = importer.substr(0, importer.length - 2) + 'ts';
30-
const tsFileExists = await compilerCtx.fs.access(tsFile);
31-
if (tsFileExists) {
32-
importer = tsFile;
33-
}
34-
}
35-
}
36-
37-
fromMsg = ` from ${config.sys.path.relative(config.rootDir, importer)}`;
38-
}
14+
if (importee.endsWith('/')) {
15+
importee = importee.slice(0, -1);
16+
}
3917

40-
const diagnostic = buildError(builtCtx.diagnostics);
41-
diagnostic.header = `Bundling Node Builtin${globals.has(importee) ? ` and Global` : ``}`;
42-
diagnostic.messageText = `For the import "${importee}" to be bundled${fromMsg}, ensure the "rollup-plugin-node-builtins" plugin${globals.has(importee) ? ` and "rollup-plugin-node-globals" plugin` : ``} is installed and added to the stencil config plugins. Please see the bundling docs for more information.`;
18+
if (builtIns.has(importee)) {
19+
let fromMsg = '';
20+
if (importer) {
21+
fromMsg = ` from ${config.sys.path.relative(config.rootDir, importer)}`;
4322
}
23+
const diagnostic = buildError(builtCtx.diagnostics);
24+
diagnostic.header = `Bundling Node Builtin or Global`;
25+
diagnostic.messageText = `For the import "${importee}" to be bundled${fromMsg}, ensure the "rollup-plugin-node-polyfills" plugin is installed and added to the stencil config plugins. Please see the bundling docs for more information.
26+
Further information: https://stenciljs.com/docs/module-bundling`;
4427
}
45-
4628
return null;
4729
}
4830
};
@@ -79,10 +61,7 @@ const builtIns = new Set([
7961

8062
'crypto',
8163
'fs',
82-
]);
8364

84-
const globals = new Set([
85-
'assert',
8665
'Buffer',
8766
'buffer',
8867
'global',

0 commit comments

Comments
 (0)