Skip to content

Commit 9710021

Browse files
Merge pull request #862 from typed-ember/nvp/link-updates
Use the tars directly, rather than links
2 parents 2047aec + 6af2842 commit 9710021

File tree

4 files changed

+33
-147
lines changed

4 files changed

+33
-147
lines changed

bin/link-build.mjs

Lines changed: 3 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import { writeFileSync } from 'node:fs';
2-
import { readFile, unlink, writeFile } from 'node:fs/promises';
3-
import { join } from 'node:path';
4-
51
import chalk from 'chalk';
62
import { execa } from 'execa';
73
import { mkdirp } from 'mkdirp';
84
import { rimraf } from 'rimraf';
9-
import { x as untar } from 'tar';
105

116
import { packages } from './packages.mjs';
127

@@ -36,84 +31,6 @@ const pack = pkgs.map(async (pkg) => {
3631

3732
await Promise.all(pack);
3833

39-
const unpack = pkgs.map(async (pkg) => {
40-
try {
41-
const pkgDest = join(dist, pkg.name);
42-
43-
await mkdirp(pkgDest);
44-
await rimraf(pkgDest + '/**/*');
45-
46-
const tarball = join(dist, pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`);
47-
48-
await untar({
49-
file: tarball,
50-
strip: 1,
51-
cwd: pkgDest,
52-
});
53-
54-
await unlink(tarball);
55-
56-
// https://github.com/pnpm/pnpm/issues/881
57-
const packageJsonPath = join(pkgDest, 'package.json');
58-
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));
59-
delete packageJson.devDependencies;
60-
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), {
61-
encoding: 'utf8',
62-
});
63-
64-
console.log(chalk.green(`Successfully unpacked ${pkg.name}`));
65-
} catch (error) {
66-
let message = `Failed to unpack ${pkg.name}`;
67-
68-
if (error instanceof Error) {
69-
message += `\n\n${error.stack}`;
70-
}
71-
72-
throw new Error(message);
73-
}
74-
});
75-
76-
await Promise.all(unpack);
77-
78-
const packageJson = `{
79-
"name": "glint-monorepo-built",
80-
"private": true,
81-
"overrides": {
82-
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')}
83-
}
84-
}
85-
`;
86-
87-
const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join('');
88-
89-
await writeFile(join(dist, 'package.json'), packageJson, { encoding: 'utf8' });
90-
await writeFile(join(dist, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' });
91-
92-
await execa('pnpm', ['install'], {
93-
cwd: dist,
94-
stdio: 'inherit',
95-
});
96-
97-
console.log(chalk.green(`Successfully installed packages`));
98-
99-
// Seems like there are race conditions in pnpm if we try to do these concurrently
100-
for (const pkg of pkgs) {
101-
try {
102-
const pkgDest = join(dist, pkg.name);
103-
104-
await execa('pnpm', ['link', '--global'], {
105-
cwd: pkgDest,
106-
stdio: 'inherit',
107-
});
108-
109-
console.log(chalk.green(`Successfully linked ${pkg.name}`));
110-
} catch (error) {
111-
let message = `Failed to link ${pkg.name}`;
112-
113-
if (error instanceof Error) {
114-
message += `\n\n${error.stack}`;
115-
}
116-
117-
throw new Error(message);
118-
}
119-
}
34+
console.log(
35+
chalk.green(`Successfully packed all packages. Ready for linking in external project.`),
36+
);

bin/link-install.mjs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { readFileSync } from 'node:fs';
1+
import { readFileSync, writeFileSync } from 'node:fs';
22
import path from 'node:path';
33
import chalk from 'chalk';
4-
import { execa } from 'execa';
54
import { glob } from 'glob';
65
import assert from 'node:assert';
76

87
const rootDir = new URL('..', import.meta.url).pathname;
9-
108
const CWD = process.cwd();
119

10+
const friendlyCWD = CWD.replace(process.env.HOME, '~');
11+
const friendlyRoot = rootDir.replace(process.env.HOME, '~');
12+
1213
assert(
1314
CWD !== rootDir,
1415
`Cannot run link-install from the glint monorepo. Must be ran from an external project`,
@@ -27,26 +28,48 @@ function shouldLink(dep) {
2728
return dep.startsWith('@glint/');
2829
}
2930

31+
const tars = glob.sync('*.tgz', {
32+
cwd: path.join(rootDir, 'dist'),
33+
});
34+
35+
console.log(tars);
36+
3037
const link = packageJsonPaths.map(async (packageJsonPath) => {
3138
const packagePath = path.dirname(packageJsonPath);
3239

3340
try {
3441
const packageJson = JSON.parse(await readFileSync(packageJsonPath, { encoding: 'utf8' }));
3542

36-
const friendlyCWD = CWD.replace(process.env.HOME, '~');
37-
const friendlyRoot = rootDir.replace(process.env.HOME, '~');
3843
console.log(`Gathering packages from ${chalk.gray(friendlyRoot)}`);
3944

4045
for (const [dep] of [
4146
...Object.entries(packageJson.dependencies ?? {}),
4247
...Object.entries(packageJson.devDependencies ?? {}),
4348
]) {
4449
if (shouldLink(dep)) {
50+
let tarified = dep.replace('@', '').replace('/', '-');
51+
let tar = tars.find((x) => x.startsWith(tarified));
52+
53+
if (!tar) {
54+
console.warn(`Could not find mapping to ${dep} from ${packagePath} using ${tarified}`);
55+
continue;
56+
}
57+
58+
let tarPath = path.join(rootDir, 'dist', tar);
59+
let relativeTarPath = path.relative(packagePath, tarPath);
60+
4561
// eslint-disable-next-line no-console
46-
console.log(`Linking ${chalk.yellow(dep)} within ${chalk.grey(friendlyCWD)}`);
47-
await execa('pnpm', ['link', '--global', dep], { cwd: packagePath });
62+
console.log(
63+
`Linking ${chalk.yellow(dep)} within ${chalk.grey(friendlyCWD)} to ${chalk.green(relativeTarPath)}`,
64+
);
65+
66+
packageJson.pnpm ||= {};
67+
packageJson.pnpm.overrides ||= {};
68+
Object.assign(packageJson.pnpm.overrides, {});
4869
}
4970
}
71+
72+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
5073
} catch (error) {
5174
let message = `Failed to link ${packagePath}`;
5275

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"execa": "^9.5.2",
2424
"mkdirp": "^3.0.1",
2525
"rimraf": "^6.0.1",
26-
"tar": "^7.4.3",
2726
"@glimmer/component": "^2.0.0",
2827
"@glint/tsserver-plugin": "workspace:*",
2928
"@typescript-eslint/eslint-plugin": "^5.42.1",

pnpm-lock.yaml

Lines changed: 0 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)