-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The purpose of this is to restore a working setup where we can link all glimmer-vm to ember.js without publishing. Previously this was just a script that `yarn link` on both sides. It seems like we tried to use `yalc` at some point. Neither of those other solutions fully works with the constraints: * supports pnpm * supports pnpm workspace * supports `publishConfig` * resolve internal dependencies (like `@glimmer/encoder`) when linked This script makes it work with all of the above. Usage: 1. pnpm install, develop, make changes, etc 2. pnpm build 3. pnpm link:all 4. pnpm link:glimmer-vm from ember.js 5. validate, iterate, re-run pnpm build/pnpm link:all as needed 6. pnpm unlink from ember.js 7. pnpm unlink:all here See also emberjs/ember.js#20590
- Loading branch information
1 parent
bb7faf4
commit 3b9789a
Showing
13 changed files
with
467 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
/bower_components/ | ||
/node_modules/ | ||
**/node_modules/ | ||
**/.yalc/ | ||
|
||
# misc | ||
/coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { readFile, writeFile, unlink } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
import chalk from 'chalk'; | ||
import { execa } from 'execa'; | ||
import { mkdirp } from 'mkdirp'; | ||
import { rimraf } from 'rimraf'; | ||
import { x as untar } from 'tar'; | ||
import { packages } from './packages.mjs'; | ||
import { writeFileSync } from 'node:fs'; | ||
|
||
const dest = new URL('../linkable-dist', import.meta.url).pathname; | ||
const pkgs = packages('@glimmer'); | ||
|
||
await mkdirp(dest); | ||
await rimraf(dest + '/*.tgz', { glob: true }); | ||
|
||
const pack = pkgs.map(async (pkg) => { | ||
try { | ||
await execa('pnpm', ['pack', '--pack-destination', dest], { | ||
cwd: pkg.path, | ||
}); | ||
|
||
console.log(chalk.green(`Successfully packed ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to pack ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
}); | ||
|
||
await Promise.all(pack); | ||
|
||
const unpack = pkgs.map(async (pkg) => { | ||
try { | ||
const pkgDest = join(dest, pkg.name); | ||
|
||
await mkdirp(pkgDest); | ||
await rimraf(pkgDest + '/**/*'); | ||
|
||
const tarball = join(dest, pkg.name.replace('@', '').replace('/', '-') + `-${pkg.version}.tgz`); | ||
|
||
await untar({ | ||
file: tarball, | ||
strip: 1, | ||
cwd: pkgDest, | ||
}); | ||
|
||
await unlink(tarball); | ||
|
||
// https://github.com/pnpm/pnpm/issues/881 | ||
const packageJsonPath = join(pkgDest, 'package.json'); | ||
const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' })); | ||
delete packageJson.devDependencies; | ||
await writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), { | ||
encoding: 'utf8', | ||
}); | ||
|
||
console.log(chalk.green(`Successfully unpacked ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to unpack ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
}); | ||
|
||
await Promise.all(unpack); | ||
|
||
const packageJson = `{ | ||
"name": "linkable-dist", | ||
"private": true, | ||
"overrides": { | ||
${pkgs.map((pkg) => ` "${pkg.name}": "workspace:*"`).join(',\n')} | ||
} | ||
} | ||
`; | ||
|
||
const workspaceYaml = 'packages:\n' + pkgs.map((pkg) => ` - '${pkg.name}'\n`).join(''); | ||
|
||
await writeFile(join(dest, 'package.json'), packageJson, { encoding: 'utf8' }); | ||
await writeFile(join(dest, 'pnpm-workspace.yaml'), workspaceYaml, { encoding: 'utf8' }); | ||
|
||
await execa('pnpm', ['install'], { | ||
cwd: dest, | ||
stdio: 'inherit', | ||
}); | ||
|
||
console.log(chalk.green(`Successfully installed packages`)); | ||
|
||
// Seems like there are race conditions in pnpm if we try to do these concurrently | ||
for (const pkg of pkgs) { | ||
try { | ||
const pkgDest = join(dest, pkg.name); | ||
|
||
await execa('pnpm', ['link', '--global'], { | ||
cwd: pkgDest, | ||
}); | ||
|
||
console.log(chalk.green(`Successfully linked ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to link ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import chalk from 'chalk'; | ||
import { execa } from 'execa'; | ||
import { rimraf } from 'rimraf'; | ||
import { packages } from './packages.mjs'; | ||
|
||
for (const pkg of packages('@glimmer')) { | ||
try { | ||
await execa('pnpm', ['uninstall', '--global', pkg.name]); | ||
|
||
console.log(chalk.green(`Successfully unlinked ${pkg.name}`)); | ||
} catch (error: unknown) { | ||
let message = `Failed to unlink ${pkg.name}`; | ||
|
||
if (error instanceof Error) { | ||
message += `\n\n${error.stack}`; | ||
} | ||
|
||
throw new Error(message); | ||
} | ||
} | ||
|
||
const dest = new URL('../linkable-dist', import.meta.url).pathname; | ||
await rimraf(dest); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.