From 2b7149cf96b2671e059f624d4d5df253f7f6f528 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 29 Jun 2023 15:23:47 +0100 Subject: [PATCH 1/2] add a failing test for addon import node_modules --- tests/scenarios/compat-addon-import-test.ts | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/scenarios/compat-addon-import-test.ts diff --git a/tests/scenarios/compat-addon-import-test.ts b/tests/scenarios/compat-addon-import-test.ts new file mode 100644 index 000000000..3919d45c8 --- /dev/null +++ b/tests/scenarios/compat-addon-import-test.ts @@ -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; })());`); + }); + }); + }); From 7de8cf8d07005b324ab03592b2ea7aac68da14cf Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 29 Jun 2023 15:48:56 +0100 Subject: [PATCH 2/2] fix node_modules in synthesized vendor --- packages/compat/src/compat-addons.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/compat/src/compat-addons.ts b/packages/compat/src/compat-addons.ts index 8095bdafa..ef9c4b195 100644 --- a/packages/compat/src/compat-addons.ts +++ b/packages/compat/src/compat-addons.ts @@ -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') ); }