Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional
importer
parameter to this.emitFile
- Loading branch information
1 parent
c0b73e4
commit 5e15861
Showing
22 changed files
with
141 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path'); | ||
let noImporterReferenceId; | ||
let mainReferenceId; | ||
let nestedReferenceId; | ||
|
||
module.exports = { | ||
description: 'allows specifying an importer when resolving ids', | ||
options: { | ||
input: 'main', | ||
plugins: { | ||
buildStart() { | ||
noImporterReferenceId = this.emitFile({ type: 'chunk', id: './lib.js' }); | ||
mainReferenceId = this.emitFile({ | ||
type: 'chunk', | ||
id: './lib.js', | ||
importer: path.resolve(__dirname, 'main.js') | ||
}); | ||
nestedReferenceId = this.emitFile({ | ||
type: 'chunk', | ||
id: './lib.js', | ||
importer: path.resolve(__dirname, 'nested/virtual.js') | ||
}); | ||
}, | ||
transform(code, id) { | ||
if (id.endsWith('main.js')) { | ||
return ( | ||
`console.log('no importer', import.meta.ROLLUP_FILE_URL_${noImporterReferenceId});\n` + | ||
`console.log('from maim', import.meta.ROLLUP_FILE_URL_${mainReferenceId});\n` + | ||
`console.log('from nested', import.meta.ROLLUP_FILE_URL_${nestedReferenceId});\n` | ||
); | ||
} | ||
} | ||
} | ||
} | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/amd/generated-lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('main lib'); | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
.../chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/amd/generated-lib2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define(function () { 'use strict'; | ||
|
||
console.log('nested lib'); | ||
|
||
}); |
7 changes: 7 additions & 0 deletions
7
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/amd/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
define(['require'], function (require) { 'use strict'; | ||
|
||
console.log('no importer', new URL(require.toUrl('./generated-lib.js'), document.baseURI).href); | ||
console.log('from maim', new URL(require.toUrl('./generated-lib.js'), document.baseURI).href); | ||
console.log('from nested', new URL(require.toUrl('./generated-lib2.js'), document.baseURI).href); | ||
|
||
}); |
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/cjs/generated-lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('main lib'); |
3 changes: 3 additions & 0 deletions
3
.../chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/cjs/generated-lib2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
console.log('nested lib'); |
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/cjs/main.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/es/generated-lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main lib'); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/es/generated-lib2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('nested lib'); |
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/es/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
console.log('no importer', new URL('generated-lib.js', import.meta.url).href); | ||
console.log('from maim', new URL('generated-lib.js', import.meta.url).href); | ||
console.log('from nested', new URL('generated-lib2.js', import.meta.url).href); |
10 changes: 10 additions & 0 deletions
10
...hunking-form/samples/emit-file/emit-chunk-with-importer/_expected/system/generated-lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function () { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('main lib'); | ||
|
||
} | ||
}; | ||
}); |
10 changes: 10 additions & 0 deletions
10
...unking-form/samples/emit-file/emit-chunk-with-importer/_expected/system/generated-lib2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
System.register([], function () { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('nested lib'); | ||
|
||
} | ||
}; | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/chunking-form/samples/emit-file/emit-chunk-with-importer/_expected/system/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
console.log('no importer', new URL('generated-lib.js', module.meta.url).href); | ||
console.log('from maim', new URL('generated-lib.js', module.meta.url).href); | ||
console.log('from nested', new URL('generated-lib2.js', module.meta.url).href); | ||
|
||
} | ||
}; | ||
}); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/emit-chunk-with-importer/lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('main lib'); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/emit-chunk-with-importer/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('ignored'); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/emit-file/emit-chunk-with-importer/nested/lib.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('nested lib'); |