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

Strip extension from reexport of rollup-app-reexports #1215

Merged
merged 1 commit into from
Jun 9, 2022
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
6 changes: 5 additions & 1 deletion packages/addon-dev/src/rollup-app-reexports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readJsonSync, writeJsonSync } from 'fs-extra';
import { extname } from 'path';
import minimatch from 'minimatch';
import type { Plugin } from 'rollup';

Expand All @@ -24,7 +25,10 @@ export default function appReexports(opts: {
this.emitFile({
type: 'asset',
fileName: `_app_/${appFilename}`,
source: `export { default } from "${pkg.name}/${addonFilename}";\n`,
source: `export { default } from "${pkg.name}/${addonFilename.slice(
0,
-extname(addonFilename).length
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to not hardcode the .js extension here for whatever (stupid) reason, but thinking about it again that's probably useless, as a reexport can only refer to js files!?

)}";\n`,
});
}
}
Expand Down
28 changes: 21 additions & 7 deletions tests/scenarios/v2-addon-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { appScenarios, baseV2Addon } from './scenarios';
import { PreparedApp } from 'scenario-tester';
import QUnit from 'qunit';
import merge from 'lodash/merge';
import { pathExistsSync, readJsonSync } from 'fs-extra';
import { pathExistsSync, readJsonSync, readFileSync } from 'fs-extra';

const { module: Qmodule, test } = QUnit;

Expand Down Expand Up @@ -202,12 +202,26 @@ appScenarios

test('the addon was built successfully', async function (assert) {
let { dir } = inDependency(app, 'v2-addon');
let files: string[] = Object.values(readJsonSync(path.join(dir, 'package.json'))['ember-addon']['app-js']);

assert.expect(files.length);

for (let pathName of files) {
assert.deepEqual(pathExistsSync(path.join(dir, pathName)), true, `pathExists: ${pathName}`);
let expectedModules = {
'./dist/_app_/components/demo/index.js': 'export { default } from "v2-addon/components/demo/index";\n',
'./dist/_app_/components/demo/out.js': 'export { default } from "v2-addon/components/demo/out";\n',
'./dist/_app_/components/demo/namespace/namespace-me.js':
'export { default } from "v2-addon/components/demo/namespace-me";\n',
};

assert.strictEqual(
Object.keys(readJsonSync(path.join(dir, 'package.json'))['ember-addon']['app-js']).length,
Object.keys(expectedModules).length
);

for (let [pathName, moduleContents] of Object.entries(expectedModules)) {
let filePath = path.join(dir, pathName);
assert.deepEqual(pathExistsSync(filePath), true, `pathExists: ${pathName}`);
assert.strictEqual(
readFileSync(filePath, { encoding: 'utf8' }),
moduleContents,
`has correct reexport: ${pathName}`
);
}
});
});
Expand Down