forked from embroider-build/ember-auto-import
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for Ember addons that opt-in to node's ES module syntax via type=module. When writing to a directory whose package.json is controlled by a third party, maximum compatibility is achieved by writing either `.cjs` or `.mjs` files as appropriate, and not `.js` files. If neither package is concerned with backwards compatibility, writing ES modules into a `.js` file can be fine, but writing commonjs modules into a `.js` file in a directory whose package.json is controlled by a third party (e.g. another package) is not generally going to be forwards-compatible Co-authored-by: Robert Jackson <rjackson@linkedin.com>
- Loading branch information
Showing
2 changed files
with
49 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import merge from 'lodash/merge'; | ||
import { Scenarios } from 'scenario-tester'; | ||
import { baseApp } from './scenarios'; | ||
import { PreparedApp } from 'scenario-tester'; | ||
import QUnit from 'qunit'; | ||
const { module: Qmodule, test } = QUnit; | ||
|
||
let template = Scenarios.fromProject(baseApp); | ||
|
||
template | ||
.map('node ES modules', project => { | ||
project.linkDevDependency('ember-auto-import', { baseDir: __dirname }); | ||
// Support for ember-cli internally to respect `ember-cli-build.cjs` landed in https://github.com/ember-cli/ember-cli/pull/10053 | ||
project.linkDevDependency('ember-cli', { baseDir: __dirname }); | ||
project.linkDependency('webpack', { baseDir: __dirname }); | ||
|
||
project.files['ember-cli-build.cjs'] = project.files['ember-cli-build.js']; | ||
delete project.files['ember-cli-build.js']; | ||
|
||
project.files['testem.cjs'] = project.files['testem.js']; | ||
delete project.files['testem.js']; | ||
|
||
project.pkg.type = 'module'; | ||
project.pkg.scripts = project.pkg.scripts || {}; | ||
project.pkg.scripts.test = 'node ./node_modules/ember-cli/bin/ember test --config-file testem.cjs'; | ||
merge(project.files, { | ||
config: { | ||
'package.json': JSON.stringify({ type: 'commonjs' }), | ||
}, | ||
}); | ||
}) | ||
.forEachScenario(scenario => { | ||
Qmodule(scenario.name, function (hooks) { | ||
let app: PreparedApp; | ||
hooks.before(async () => { | ||
app = await scenario.prepare(); | ||
}); | ||
test('npm run test', async function (assert) { | ||
console.log(app.dir); | ||
let result = await app.execute('volta run npm -- run test'); | ||
assert.equal(result.exitCode, 0, result.output); | ||
}); | ||
}); | ||
}); |