Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix this.import from node_modules in v1 addons #1488

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; })());`);
});
});
});