Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): Expose cjs detection and support offline caching
BREAKING CHANGES: Raises minimal required Rollup version to 2.30.0
- Loading branch information
1 parent
ae30f42
commit 305605d
Showing
15 changed files
with
605 additions
and
121 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
33 changes: 33 additions & 0 deletions
33
packages/commonjs/test/fixtures/function/expose-file-type-detection/_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,33 @@ | ||
const path = require('path'); | ||
|
||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
const ID_OTHER = path.join(__dirname, 'other.js'); | ||
|
||
module.exports = { | ||
description: 'exposes cjs file type detection to other plugins', | ||
options: { | ||
input: [ID_MAIN, ID_OTHER], | ||
plugins: [ | ||
{ | ||
moduleParsed({ | ||
id, | ||
meta: { | ||
commonjs: { isCommonJS } | ||
} | ||
}) { | ||
if (id === ID_MAIN) { | ||
if (isCommonJS !== false) { | ||
throw new Error( | ||
`Main file wrongly detected: isCommonJS === ${JSON.stringify(isCommonJS)}` | ||
); | ||
} | ||
} else if (isCommonJS !== true) { | ||
throw new Error( | ||
`Other file wrongly detected: isCommonJS === ${JSON.stringify(isCommonJS)}` | ||
); | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/expose-file-type-detection/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 @@ | ||
import foo from './other.js'; | ||
|
||
t.is(foo, 'foo'); |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/expose-file-type-detection/other.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 @@ | ||
module.exports = 'foo'; |
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 @@ | ||
exports.dep = 42; |
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 @@ | ||
const dep = require('./dep'); | ||
|
||
console.log(dep); |
20 changes: 20 additions & 0 deletions
20
packages/commonjs/test/fixtures/samples/caching/rollupWorker.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,20 @@ | ||
const { workerData, parentPort } = require('worker_threads'); | ||
|
||
const { rollup } = require('rollup'); | ||
|
||
const commonjs = require('../../../../dist/index'); | ||
const { getCodeFromBundle } = require('../../../helpers/util'); | ||
|
||
generateCode(workerData); | ||
|
||
async function generateCode(cache) { | ||
const code = await getCodeFromBundle( | ||
await rollup({ | ||
input: 'fixtures/samples/caching/main.js', | ||
cache, | ||
plugins: [commonjs()] | ||
}) | ||
); | ||
|
||
parentPort.postMessage(code); | ||
} |
Oops, something went wrong.