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

support new embroider working dir introduced in embroider/compat >3.1 #387

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 19 additions & 10 deletions packages/ember-cli-code-coverage/index.js
Expand Up @@ -55,10 +55,23 @@
}

if (opts.embroider === true) {
let {
stableWorkspaceDir,
} = require('@embroider/compat/src/default-pipeline');
cwd = stableWorkspaceDir(cwd, process.env.EMBER_ENV);
let version = pkgJSON['devDependencies']['@embroider/compat'];
let semver = require('semver');

Check failure on line 59 in packages/ember-cli-code-coverage/index.js

View workflow job for this annotation

GitHub Actions / Tests

"semver" is extraneous
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This admittedly feels flimsy, but this.project was not available in scope here (to pass on to something like ember-cli-version-checker)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps a try/catch for importing/requiring the new locateEmbroiderWorkingDir method

Copy link
Contributor Author

@chrismllr chrismllr Nov 18, 2023

Choose a reason for hiding this comment

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

Going to migrate to use the above, saw some issues in tests with fixturify-project usage (these values read were not the fixture libs output). This method also feels more stable. If the method exists, use it. Otherwise, use the original.


let usesNewTempDirLocation = semver.satisfies(
semver.valid(semver.coerce(version)),
'>3.1'
);

if (usesNewTempDirLocation) {
let { locateEmbroiderWorkingDir } = require('@embroider/core');
cwd = path.resolve(locateEmbroiderWorkingDir(cwd), 'rewritten-app');
} else {
let {
stableWorkspaceDir,
} = require('@embroider/compat/src/default-pipeline');
cwd = stableWorkspaceDir(cwd, process.env.EMBER_ENV);
}
}

const IstanbulPlugin = require.resolve('babel-plugin-istanbul');
Expand Down Expand Up @@ -115,12 +128,8 @@
* If coverage is enabled attach coverage middleware to the express server run by ember-cli
* @param {Object} startOptions - Express server start options
*/
serverMiddleware(startOptions) {
attachMiddleware.serverMiddleware(startOptions.app, {
configPath: this.project.configPath(),
root: this.project.root,
namespaceMappings: this.buildNamespaceMappings(),
});
serverMiddleware(startOptions, config) {
attachMiddleware.serverMiddleware(startOptions.app, config);
},

testemMiddleware(app) {
Expand Down
11 changes: 9 additions & 2 deletions packages/ember-cli-code-coverage/lib/attach-middleware.js
Expand Up @@ -22,8 +22,15 @@ function logError(err, req, res, next) {
* in-repo-namespace/components/foo.js.
*/
function normalizeRelativePath(root, filepath) {
let embroiderTmpPathRegex = /embroider\/.{6}/gm;
let relativePath = filepath.split(embroiderTmpPathRegex)[1].slice(1);
let relativePath;
let embroiderCompatLT31TmpPathRegex = /embroider\/.{6}/gm;
let embroiderCompatGT31TmpPathRegex = /\.embroider\/rewritten-app\//gm;

if (embroiderCompatGT31TmpPathRegex.test(filepath)) {
relativePath = filepath.split(embroiderCompatGT31TmpPathRegex)[1];
} else {
relativePath = filepath.split(embroiderCompatLT31TmpPathRegex)[1].slice(1);
}

if (fs.existsSync(path.join(root, 'package.json'))) {
let pkgJSON = fs.readJsonSync(path.join(root, 'package.json'));
Expand Down