-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap preprocesor tree with moduleName before transform
- Loading branch information
Matthew Edwards
committed
May 19, 2022
1 parent
93148c4
commit 5316f55
Showing
4 changed files
with
168 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { Project, BuildResult, expectFilesAt, ExpectFile } from '@embroider/test-support'; | ||
import { throwOnWarnings } from '@embroider/core'; | ||
import merge from 'lodash/merge'; | ||
|
||
describe('preprocessors tests', function () { | ||
jest.setTimeout(120000); | ||
let build: BuildResult; | ||
let app: Project; | ||
let expectFile: ExpectFile; | ||
|
||
throwOnWarnings(); | ||
|
||
beforeAll(async function () { | ||
app = Project.emberNew('my-app'); | ||
|
||
const PACKAGE_MY_PREPROCESSOR = 'my-preprocessor'; | ||
|
||
merge(app.files, { | ||
config: { | ||
'targets.js': `module.exports = { browsers: ['last 1 Chrome versions'] }`, | ||
}, | ||
app: { | ||
components: { | ||
'from-the-app.js': ` | ||
import Component from '@glimmer/component'; | ||
export default class extends Component {} | ||
`, | ||
'from-the-app.hbs': `<div>{{this.title}}</div><Greeting/>`, | ||
}, | ||
}, | ||
}); | ||
|
||
let addonPreprocessor = app.addAddon(PACKAGE_MY_PREPROCESSOR); | ||
|
||
const INDEX_JS_WITH_PREPROCESSOR = `const { map } = require('broccoli-stew'); | ||
module.exports = { | ||
name: require('./package').name, | ||
setupPreprocessorRegistry(type, registry) { | ||
if (type !== 'parent') { | ||
return; | ||
} | ||
registry.add('js', { | ||
name: 'special-path-processor', | ||
toTree(tree, inputPath) { | ||
if (inputPath !== '/') { | ||
return tree; | ||
} | ||
let augmented = map( | ||
tree, | ||
'**/*.{js,css}', | ||
function (content, relativePath) { | ||
console.log('$$$$' + relativePath); | ||
return \`/*path@\${relativePath}*/\n\${content}\`; | ||
} | ||
); | ||
return augmented; | ||
}, | ||
}); | ||
} | ||
}; | ||
`; | ||
|
||
addonPreprocessor.linkDevPackage('broccoli-stew'); | ||
addonPreprocessor.files['index.js'] = INDEX_JS_WITH_PREPROCESSOR; | ||
|
||
let addon = app.addAddon('my-addon'); | ||
|
||
merge(addon.files, { | ||
app: { | ||
components: { | ||
'greeting.js': `export { default } from 'my-addon/components/greeting';`, | ||
}, | ||
}, | ||
addon: { | ||
components: { | ||
'greeting.js': ` | ||
import Component from '@glimmer/component'; | ||
export default class extends Component {} | ||
`, | ||
'greeting.hbs': `Hello World`, | ||
}, | ||
}, | ||
}); | ||
|
||
addon.addDependency(PACKAGE_MY_PREPROCESSOR); | ||
|
||
build = await BuildResult.build(app, { | ||
stage: 2, | ||
type: 'app', | ||
emberAppOptions: { | ||
tests: false, | ||
}, | ||
}); | ||
expectFile = expectFilesAt(build.outputPath); | ||
}); | ||
|
||
afterAll(async () => { | ||
await build.cleanup(); | ||
}); | ||
|
||
test('dependencies are setup for this test suite correctly', () => { | ||
expectFile('package.json').exists(); | ||
expectFile('package.json').matches(/my-preprocessor/, 'has the preprocessor dependency'); | ||
expectFile('node_modules/my-addon/package.json').exists(); | ||
expectFile('node_modules/my-addon/package.json').matches(/my-preprocessor/, 'has the preprocessor dependency'); | ||
expectFile('node_modules/my-preprocessor/package.json').exists(); | ||
}); | ||
|
||
test.skip('app has correct path embedded in comment', () => { | ||
const assertFile = expectFile('components/from-the-app.js'); | ||
assertFile.exists(); | ||
// This is the expected output during an classic build. | ||
assertFile.matches(/path:my-app\/components\/from-the-app\.js/, 'has a path comment in app components'); | ||
}); | ||
|
||
test('addon has correct path embedded in comment', () => { | ||
expectFile('node_modules/my-preprocessor/package.json').exists(); | ||
const assertFile = expectFile('node_modules/my-addon/components/greeting.js'); | ||
assertFile.matches(/\/\/path:my-addon\/components\/from-the-app\.js/, 'has a path comment in app components'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -5649,7 +5649,15 @@ browserify-zlib@^0.2.0: | |
dependencies: | ||
pako "~1.0.5" | ||
|
||
browserslist@^3.2.6, browserslist@^4.0.0, browserslist@^4.14.0, browserslist@^4.14.5, browserslist@^4.17.5, browserslist@^4.19.1: | ||
browserslist@^3.2.6: | ||
version "3.2.8" | ||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" | ||
integrity sha512-WHVocJYavUwVgVViC0ORikPHQquXwVh939TaelZ4WDqpWgTX/FsGhl/+P4qBUAGcRvtOgDgC+xftNWWp2RUTAQ== | ||
dependencies: | ||
caniuse-lite "^1.0.30000844" | ||
electron-to-chromium "^1.3.47" | ||
|
||
browserslist@^4.0.0, browserslist@^4.14.5, browserslist@^4.17.5, browserslist@^4.19.1: | ||
version "4.19.1" | ||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.1.tgz#4ac0435b35ab655896c31d53018b6dd5e9e4c9a3" | ||
integrity sha512-u2tbbG5PdKRTUoctO3NBD8FQ5HdPh1ZXPHzp1rwaa5jTc+RV9/+RlWiAIKmjRPQF+xbGM9Kklj5bZQFa2s/38A== | ||
|
@@ -5894,6 +5902,11 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001286: | |
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz#e0ee78b9bec0704f67304b00ff3c5c0c768a9f62" | ||
integrity sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA== | ||
|
||
caniuse-lite@^1.0.30000844: | ||
version "1.0.30001341" | ||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001341.tgz#59590c8ffa8b5939cf4161f00827b8873ad72498" | ||
integrity sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA== | ||
|
||
capture-exit@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" | ||
|
@@ -7125,6 +7138,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" | ||
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= | ||
|
||
electron-to-chromium@^1.3.47: | ||
version "1.4.137" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.137.tgz#186180a45617283f1c012284458510cd99d6787f" | ||
integrity sha512-0Rcpald12O11BUogJagX3HsCN3FE83DSqWjgXoHo5a72KUKMSfI39XBgJpgNNxS9fuGzytaFjE06kZkiVFy2qA== | ||
|
||
electron-to-chromium@^1.4.17: | ||
version "1.4.66" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.66.tgz#d7453d363dcd7b06ed1757adcde34d724e27b367" | ||
|
@@ -10046,18 +10064,6 @@ fireworm@^0.7.0: | |
lodash.flatten "^3.0.2" | ||
minimatch "^3.0.2" | ||
|
||
[email protected], fixturify-project@^4.0.1: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/fixturify-project/-/fixturify-project-4.1.0.tgz#92a4e74859321a37a5671a40f1f14297141a83c1" | ||
integrity sha512-ywz2jaAmXbRkZSSBBQuAabfqeB1Ccy27zcl/4IcvwPHmv9aMLXyXtq/OtfP4MMNrqG//JxjSPsgLtqohFZEwdg== | ||
dependencies: | ||
bin-links "^3.0.0" | ||
fixturify "^2.1.1" | ||
resolve-package-path "^3.1.0" | ||
tmp "^0.0.33" | ||
type-fest "^2.3.2" | ||
walk-sync "^3.0.0" | ||
|
||
fixturify-project@^1.10.0: | ||
version "1.10.0" | ||
resolved "https://registry.yarnpkg.com/fixturify-project/-/fixturify-project-1.10.0.tgz#091c452a9bb15f09b6b9cc7cf5c0ad559f1d9aad" | ||
|
@@ -10075,6 +10081,18 @@ fixturify-project@^2.1.0, fixturify-project@^2.1.1: | |
tmp "^0.0.33" | ||
type-fest "^0.11.0" | ||
|
||
fixturify-project@^4.0.1: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/fixturify-project/-/fixturify-project-4.1.0.tgz#92a4e74859321a37a5671a40f1f14297141a83c1" | ||
integrity sha512-ywz2jaAmXbRkZSSBBQuAabfqeB1Ccy27zcl/4IcvwPHmv9aMLXyXtq/OtfP4MMNrqG//JxjSPsgLtqohFZEwdg== | ||
dependencies: | ||
bin-links "^3.0.0" | ||
fixturify "^2.1.1" | ||
resolve-package-path "^3.1.0" | ||
tmp "^0.0.33" | ||
type-fest "^2.3.2" | ||
walk-sync "^3.0.0" | ||
|
||
fixturify@^0.3.2: | ||
version "0.3.4" | ||
resolved "https://registry.yarnpkg.com/fixturify/-/fixturify-0.3.4.tgz#c676de404a7f8ee8e64d0b76118e62ec95ab7b25" | ||
|
@@ -14995,7 +15013,7 @@ qunit-dom@^1.6.0: | |
ember-cli-babel "^7.23.0" | ||
ember-cli-version-checker "^5.1.1" | ||
|
||
qunit@^2.14.1, qunit@^2.16.0: | ||
qunit@^2.16.0: | ||
version "2.17.2" | ||
resolved "https://registry.yarnpkg.com/qunit/-/qunit-2.17.2.tgz#5cb278e131d931f25c109a0fdb0518be7754c25a" | ||
integrity sha512-17isVvuOmALzsPjiV7wFg/6O5vJYXBrQZPwocfQSSh0I/rXvfX7bKMFJ4GMVW3U4P8r2mBeUy8EAngti4QD2Vw== | ||
|