Skip to content

Commit

Permalink
Merge pull request #1488 from embroider-build/app-import-node-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 authored Jun 29, 2023
2 parents 9f97d6e + 7de8cf8 commit 7532326
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
5 changes: 1 addition & 4 deletions packages/compat/src/compat-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export default class CompatAddons implements Stage {
if (!this.treeSync) {
this.treeSync = new TreeSync(
addons,
resolve(locateEmbroiderWorkingDir(this.compatApp.root), 'rewritten-packages'),
{
ignore: ['**/node_modules'],
}
resolve(locateEmbroiderWorkingDir(this.compatApp.root), 'rewritten-packages')
);
}

Expand Down
60 changes: 60 additions & 0 deletions tests/scenarios/compat-addon-import-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { expectFilesAt, ExpectFile } from '@embroider/test-support/file-assertions/qunit';
import { PreparedApp } from 'scenario-tester';
import { throwOnWarnings } from '@embroider/core';
import { appScenarios, baseAddon } from './scenarios';
import QUnit from 'qunit';
import { merge } from 'lodash';
const { module: Qmodule, test } = QUnit;

appScenarios
.map('compat-addon-import', project => {
let addon1 = baseAddon();
addon1.pkg.name = 'my-addon1';

merge(addon1.files, {
'index.js': `
module.exports = {
name: require('./package.json').name,
included(app) {
this.import('node_modules/third-party1/index.js', {
using: [{ transformation: 'amd' }],
type: 'test'
});
}
}
`,
});

addon1.addDependency('third-party1', '1.2.3').files = {
'index.js': 'module.exports = function() { console.log("hello world"); }',
};

project.addDependency(addon1);
})
.forEachScenario(scenario => {
Qmodule(scenario.name, function (hooks) {
throwOnWarnings(hooks);

let app: PreparedApp;

let expectFile: ExpectFile;

hooks.before(async assert => {
app = await scenario.prepare();
let result = await app.execute('ember build', { env: { STAGE1_ONLY: 'true' } });
assert.equal(result.exitCode, 0, result.output);
});

hooks.beforeEach(assert => {
expectFile = expectFilesAt(app.dir, { qunit: assert });
});

test('synthesized-vendor has imported file in node modules', function () {
expectFile(
'./node_modules/.embroider/rewritten-packages/@embroider/synthesized-vendor/node_modules/third-party1/index.js'
).matches(`(function(define){
module.exports = function() { console.log(\"hello world\"); }
})((function(){ function newDefine(){ var args = Array.prototype.slice.call(arguments); return define.apply(null, args); }; newDefine.amd = true; return newDefine; })());`);
});
});
});

0 comments on commit 7532326

Please sign in to comment.