Skip to content

Commit

Permalink
[wip] change the structure of rewritten-packages
Browse files Browse the repository at this point in the history
This is intended to help vite and esbuild discover our packages better
  • Loading branch information
mansona committed Oct 5, 2023
1 parent 9bd2b1d commit b23c2c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion packages/compat/src/compat-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export default class CompatAddons implements Stage {

async ready(): Promise<{ outputPath: string }> {
return {
outputPath: resolve(locateEmbroiderWorkingDir(this.compatApp.root), 'rewritten-app'),
outputPath: resolve(
locateEmbroiderWorkingDir(this.compatApp.root),
'rewritten-app',
'node_modules',
this.compatApp.name
),
};
}

Expand Down
11 changes: 8 additions & 3 deletions packages/compat/src/standalone-addon-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ ${summarizePeerDepViolations(violations)}`
return new Funnel(interior, { destDir: index.packages[pkg.root] });
});

let fakeTargets = Object.values(index.packages).map(dir => {
return writeFile(join(dir, '..', 'superFakeTarget.js'), '');
});

return broccoliMergeTrees([
...exteriorTrees,
new Funnel(compatApp.synthesizeStylesPackage(interiorTrees), {
Expand All @@ -53,6 +57,7 @@ ${summarizePeerDepViolations(violations)}`
destDir: '@embroider/synthesized-vendor',
}),
writeFile('index.json', JSON.stringify(index, null, 2)),
...fakeTargets,
]);
}

Expand All @@ -62,7 +67,7 @@ function buildAddonIndex(compatApp: CompatApp, appPackage: Package, packages: Se
extraResolutions: {},
};
for (let oldPkg of packages) {
let newRoot = `${oldPkg.name}.${hashed(oldPkg.root)}`;
let newRoot = `${oldPkg.name}.${hashed(oldPkg.root)}/node_modules/${oldPkg.name}`;
content.packages[oldPkg.root] = newRoot;
let nonResolvableDeps = oldPkg.nonResolvableDeps;
if (nonResolvableDeps) {
Expand All @@ -75,14 +80,14 @@ function buildAddonIndex(compatApp: CompatApp, appPackage: Package, packages: Se
// yet. This directory lives outside our rewritten-pacakges directory because
// it's produced by a separate build stage, and it's easier to have them
// writing into separate directories.
content.packages[compatApp.root] = join('..', 'rewritten-app');
content.packages[compatApp.root] = join('..', 'rewritten-app', 'node_modules', compatApp.name);

let nonResolvableDeps = appPackage.nonResolvableDeps;
if (nonResolvableDeps) {
let extraRoots = [...nonResolvableDeps.values()].map(v => v.root);

// the app gets extraResolutions support just like every addon does
content.extraResolutions[join('..', 'rewritten-app')] = extraRoots;
content.extraResolutions[join('..', 'rewritten-app', 'node_modules', compatApp.name)] = extraRoots;

// but it also gets extraResolutions registered against its *original*
// location, because the app is unique because stage2 needs a Package
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/module-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ export class Resolver {
return request.rehome(resolve(pkg.root, 'package.json'));
} else {
// otherwise we need to just assume that internal naming is simple
return request.alias(request.specifier.replace(pkg.name, '.')).rehome(resolve(pkg.root, 'package.json'));
return request.rehome(resolve(pkg.root, '..', 'superFakeTarget.js'));
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function esBuildResolver(root = process.cwd()): EsBuildPlugin {
let src = virtualContent(path, resolverLoader.resolver);
if (!macrosConfig) {
macrosConfig = readJSONSync(
resolve(locateEmbroiderWorkingDir(root), 'rewritten-app', 'macros-config.json')
resolve(locateEmbroiderWorkingDir(root), 'rewritten-app', 'node_modules', 'vite-app', 'macros-config.json')
) as PluginItem;
}
return { contents: runMacros(src, path, macrosConfig) };
Expand All @@ -54,7 +54,7 @@ export function esBuildResolver(root = process.cwd()): EsBuildPlugin {
}
if (!macrosConfig) {
macrosConfig = readJSONSync(
resolve(locateEmbroiderWorkingDir(root), 'rewritten-app', 'macros-config.json')
resolve(locateEmbroiderWorkingDir(root), 'rewritten-app', 'node_modules', 'vite-app', 'macros-config.json')
) as PluginItem;
}
return { contents: runMacros(src, path, macrosConfig) };
Expand Down

0 comments on commit b23c2c0

Please sign in to comment.