Skip to content

Commit bb32149

Browse files
committed
feat: support mapping and tracing plugin module
1 parent 9697503 commit bb32149

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"base64-arraybuffer": "^0.1.5",
4848
"cherow": "^1.6.9",
4949
"del": "^3.0.0",
50-
"dumber-module-loader": "^0.15.11",
50+
"dumber-module-loader": "^0.15.13",
5151
"escope": "^3.6.0",
5252
"mkdirp": "^0.5.1",
5353
"node-fetch": "^2.3.0",

spec/bundler.spec.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,16 +843,20 @@ test('Bundler traces files with paths mapping', t => {
843843
'node_modules/dumber-module-loader/dist/index.js': 'dumber-module-loader',
844844
'node_modules/foo/package.json': JSON.stringify({name: 'foo', main: 'index'}),
845845
'node_modules/foo/index.js': 'loo',
846+
'node_modules/bar/package.json': JSON.stringify({name: 'bar', main: 'index'}),
847+
'node_modules/bar/index.js': '',
848+
'node_modules/bar/el.js': '',
846849
};
847850
const bundler = createBundler(fakeFs, {
848851
paths: {
849852
'foo': 'common/foo',
853+
'el': 'bar/el',
850854
'../src': ''
851855
}
852856
});
853857

854858
Promise.resolve()
855-
.then(() => bundler.capture({path: 'src/app.js', contents: 'foo', moduleId: 'app'}))
859+
.then(() => bundler.capture({path: 'src/app.js', contents: 'el!foo', moduleId: 'app'}))
856860
.then(() => bundler.capture({path: 'src/common/foo.js', contents: '', moduleId: 'common/foo'}))
857861
.then(() => bundler.capture({path: 'test/app.spec.js', contents: '../src/app', moduleId: '../test/app.spec'}))
858862
.then(() => bundler.resolve())
@@ -865,14 +869,18 @@ test('Bundler traces files with paths mapping', t => {
865869
{contents: 'dumber-module-loader;'},
866870
{contents: 'define.switchToUserSpace();'},
867871
{path: 'test/app.spec.js', contents: "define('../test/app.spec',[\"../src/app\"],1);", sourceMap: undefined},
868-
{path: 'src/app.js', contents: "define('app',[\"foo\"],1);", sourceMap: undefined},
869-
{path: 'src/common/foo.js', contents: "define('common/foo',[],1);", sourceMap: undefined}
872+
{path: 'src/app.js', contents: "define('app',[\"el!foo\"],1);", sourceMap: undefined},
873+
{path: 'src/common/foo.js', contents: "define('common/foo',[],1);", sourceMap: undefined},
874+
{contents: 'define.switchToPackageSpace();'},
875+
{path: 'node_modules/bar/el.js', contents: "define('bar/el',[],1);", sourceMap: undefined},
876+
{contents: 'define.switchToUserSpace();'},
870877
],
871878
config: {
872879
baseUrl: '/dist',
873880
bundles: {},
874881
paths: {
875882
'foo': 'common/foo',
883+
'el': 'bar/el',
876884
'../src': ''
877885
}
878886
}

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,15 @@ export default class Bundler {
263263
const parsedId = parse(mapId(id, this._paths));
264264
if (!parsedId.prefix && parsedId.ext === '.css' && !this._isInjectCssTurnedOn) {
265265
consults.push(this._supportInjectCssIfNeeded());
266+
} else if (parsedId.prefix &&
267+
parsedId.prefix !== 'text!' &&
268+
parsedId.prefix !== 'json!' &&
269+
parsedId.prefix !== 'raw!') {
270+
// Trace any unknown plugin module.
271+
// For simplicity, push it to next resolve cycle.
272+
this._moduleIds_todo.add(parsedId.prefix.slice(0, -1));
266273
}
274+
267275
const possibleIds = nodejsIds(parsedId.bareId);
268276
if (possibleIds.some(id => this._moduleId_done.has(id))) return;
269277

0 commit comments

Comments
 (0)