Skip to content

Commit

Permalink
Merge pull request #1411 from embroider-build/pnpm
Browse files Browse the repository at this point in the history
Switch to pnpm
  • Loading branch information
ef4 authored May 10, 2023
2 parents f004d11 + 28ec9ea commit 5877484
Show file tree
Hide file tree
Showing 74 changed files with 22,922 additions and 19,459 deletions.
22 changes: 11 additions & 11 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Setup node and yarn
description: Setup node and install dependencies using yarn
name: Setup node and pnpm
description: Setup node and install dependencies using pnpm
inputs:
use_lockfile:
description: 'Whether to use the lockfile vs latest floating dependencies'
Expand All @@ -10,17 +10,17 @@ runs:
steps:
- uses: volta-cli/action@v4
env:
ACTIONS_STEP_DEBUG: true
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
ACTIONS_STEP_DEBUG: truex
- name: Get pnpm cache directory path
id: pnpm-cache-dir-path
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v3
id: yarn-cache
id: pnpm-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-v1
path: ${{ steps.pnpm-cache-dir-path.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}-v1
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install ${{ fromJSON('{"false":"--no-lockfile", "true":"--frozen-lockfile"}')[inputs.use_lockfile] }}
${{ runner.os }}-pnpm-
- run: pnpm install ${{ fromJSON('{"false":"--no-lockfile", "true":"--frozen-lockfile"}')[inputs.use_lockfile] }}
shell: bash
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
VOLTA_FEATURE_PNPM: 1

on:
schedule:
- cron: '0 7 * * *' # daily, 7am
Expand Down Expand Up @@ -28,7 +31,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- name: lint
run: yarn lint
run: pnpm lint
- id: set-matrix
working-directory: test-packages/support
run: echo "matrix=$(node ./suite-setup-util.js --matrix)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -72,7 +75,7 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
publish: yarn release
publish: pnpm release
title: 'Release Preview'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/prepare-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- main
env:
VOLTA_FEATURE_PNPM: 1
branch: "sync-changelog"
title: "[Release Prep]: Update proposed changelog"
commit: "pre-release :: add changesets"
Expand Down Expand Up @@ -32,7 +33,7 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/setup
# specify the owner so that forks with their origin poiting at the fork still query the upstream PR list
- run: yarn prepare:changelog --non-interactive
- run: pnpm prepare:changelog --non-interactive
env:
# avoiding API read throttling
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
branches:
- main

env:
VOLTA_FEATURE_PNPM: 1

concurrency:
group: publish-unstable-${{ github.head_ref || github.ref }}
cancel-in-progress: true
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# No need to run prettier here
*.md
*.yml
*.yaml
*.html
*.json

Expand Down
27 changes: 14 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

## Preparing for local development

0. `export VOLTA_FEATURE_PNPM=1` in your shell, because [Volta's PNPM support](https://github.com/volta-cli/volta/issues/737) is behind a feature flag for the present.
1. Clone this repo.
2. Run `yarn install`. This will also trigger a typescript compile.
3. If you edit the typescript, you will need to compile again via `yarn compile` or `yarn compile --watch`.
2. Run `pnpm install`. This will also trigger a typescript compile.
3. If you edit the typescript, you will need to compile again via `pnpm compile` or `pnpm compile --watch`.

## Running lints

`yarn lint` at the top of the monorepo will lint everything.
`pnpm lint` at the top of the monorepo will lint everything.

## Running tests

Tests can be run per-package, or combined all together.

Per-package test suites are defined as the `yarn test` command within each `packages/*` or `test-packages/*`.
Per-package test suites are defined as the `pnpm test` command within each `packages/*` or `test-packages/*`.

The combined suite can be run via the top-level `yarn test` command. It's defined by combining
The combined suite can be run via the top-level `pnpm test` command. It's defined by combining

- all the `yarn test:*` commands within each `packages/*` or `test-packages/*`. These are typically complete Ember apps that need to get built and tested in the browser.
- we have special handling for `ember try:each`. When you use the top-level `yarn test` locally we _don't_ run these by default, because they can't be parallelized easily. If you want to run them, just go into the specific package you care about and run `ember try:each` there.
- all the `pnpm test:*` commands within each `packages/*` or `test-packages/*`. These are typically complete Ember apps that need to get built and tested in the browser.
- we have special handling for `ember try:each`. When you use the top-level `pnpm test` locally we _don't_ run these by default, because they can't be parallelized easily. If you want to run them, just go into the specific package you care about and run `ember try:each` there.
- all Jest tests that are configured in the entire monorepo. These are typically Node unit & integration tests of the build tooling.

When you run the combined test suite locally, we emit Jest stubs for each of the various suites so that everything runs together under Jest.
Expand All @@ -29,9 +30,9 @@ When we run the combined suite in GitHub, we emit separate jobs for each separat
## Working with tests scenarios

1. `cd tests/scenarios`
2. `yarn test:list` to figure out the full name of the scenario you want. eg: `release-engines-without-fastboot`.
3. `yarn test:output --scenario release-engines-without-fastboot --outdir /path/to/wherever`. This will create the scenario as a standalone project in `/path/to/wherever`.
4. `cd /path/to/wherever` && `yarn start` to boot and debug the ember app.
2. `pnpm test:list` to figure out the full name of the scenario you want. eg: `release-engines-without-fastboot`.
3. `pnpm test:output --scenario release-engines-without-fastboot --outdir /path/to/wherever`. This will create the scenario as a standalone project in `/path/to/wherever`.
4. `cd /path/to/wherever` && `pnpm start` to boot and debug the ember app.

## Test Maintenance

Expand All @@ -40,6 +41,6 @@ In the tests directory we derive our tests off of base app and addon templates (
## Use a local version of embroider to compile your projects

1. Clone this repo.
2. Run `yarn compile` (or `yarn compile --watch`).
3. In each of the `./packages/*` directories, run `yarn link`.
4. In your app, `yarn link @embroider/core` and any other embroider packages that appear in your package.json.
2. Run `pnpm compile` (or `pnpm compile --watch`).
3. In each of the `./packages/*` directories, run `pnpm link`.
4. In your app, `pnpm link @embroider/core` and any other embroider packages that appear in your package.json.
2 changes: 1 addition & 1 deletion docs/porting-addons-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ If your addon is a mix of both build-time and run-time features, consider replac

Traditionally, an Ember addon is a single NPM package that combines both the actual addon code _and_ a "dummy" app for hosting tests and docs. This was [problematic for several reasons](https://github.com/ember-cli/rfcs/issues/119). V2 addons instead require clean separation between addon and app, so you're going to be working with more than one distinct NPM package: one for the addon, one for the test-app, and optionally one for the documentation site.

Our recommended way to manage these multiple packages is using a monorepo, via Yarn Workspaces or NPM Workspaces. The example in this guide assumes a Yarn Workspaces monorepo.
Our recommended way to manage these multiple packages is using a monorepo, via Yarn, NPM, or PNPM Workspaces. The example in this guide assumes a Yarn Workspaces monorepo.

## Part 1: Separate Addon from Dummy App

Expand Down
53 changes: 22 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,6 @@
"type": "git",
"url": "git@github.com:embroider-build/embroider.git"
},
"workspaces": {
"packages": [
"packages/*",
"test-packages/*",
"test-packages/@embroider/*",
"types/babel-core",
"types/@babel__traverse",
"types/broccoli-funnel",
"types/broccoli-concat",
"types/ember-cli-htmlbars",
"tests/scenarios",
"tests/app-template",
"tests/ts-app-template",
"tests/addon-template",
"tests/v2-addon-template"
],
"nohoist": [
"**/@types/broccoli-plugin",
"**/babel-plugin-ember-template-compilation"
]
},
"scripts": {
"postinstall": "patch-package",
"release": "changeset publish",
Expand All @@ -37,11 +16,11 @@
"lint:eslint:fix": "eslint . --fix",
"lint:prettier": "prettier . -c",
"lint:prettier:fix": "prettier . -w",
"lint:router-types": "cd packages/router && yarn lint:types",
"prepare": "tsc && yarn build-v2-addons",
"build-v2-addons": "concurrently 'yarn:build-v2-addons:*'",
"build-v2-addons:router": "cd packages/router && yarn build",
"test": "cd tests/scenarios && yarn test"
"lint:router-types": "cd packages/router && pnpm lint:types",
"prepare": "tsc && pnpm build-v2-addons",
"build-v2-addons": "concurrently 'pnpm:build-v2-addons:*'",
"build-v2-addons:router": "cd packages/router && pnpm build",
"test": "cd tests/scenarios && pnpm test"
},
"jest": {
"projects": [
Expand All @@ -53,10 +32,22 @@
"**/*.test.js"
]
},
"resolutions": {
"**/browserslist": "^4.14.0",
"**/qunit": "^2.14.1",
"**/graceful-fs": "^4.0.0"
"pnpm": {
"overrides": {
"browserslist": "^4.14.0",
"qunit": "^2.14.1",
"graceful-fs": "^4.0.0",
"@babel/types": "^7.21.5",
"@types/babel__traverse": "^7.18.5",
"@types/eslint": "^8.37.0",
"@types/ember__object": "^4.0.3",
"@types/ember__routing": "^4.0.12",
"@types/ember__application": "^4.0.5",
"@types/ember__owner": "^4.0.3",
"@types/ember__engine": "^4.0.4",
"@types/ember": "^4.0.3"

}
},
"devDependencies": {
"@changesets/cli": "^2.25.0",
Expand All @@ -80,7 +71,7 @@
},
"volta": {
"node": "16.20.0",
"yarn": "1.22.19"
"pnpm": "8.4.0"
},
"version": "1.8.3"
}
5 changes: 4 additions & 1 deletion packages/compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
"@embroider/sample-transforms": "0.0.0",
"@embroider/test-support": "0.36.0",
"@glimmer/syntax": "^0.84.2",
"@glint/template": "^1.0.0",
"@types/babel__core": "^7.1.14",
"@types/babel__generator": "^7.6.2",
"@types/babel__template": "^7.4.0",
"@types/babel__traverse": "^7.18.5",
"@types/babylon": "^6.16.5",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^9.0.11",
Expand All @@ -77,9 +79,10 @@
"@types/node": "^15.12.2",
"@types/resolve": "^1.20.0",
"@types/semver": "^7.3.6",
"broccoli-node-api": "^1.7.0",
"code-equality-assertions": "^0.9.0",
"ember-engines": "^0.8.19",
"scenario-tester": "^2.0.1",
"scenario-tester": "^2.1.2",
"typescript": "*"
},
"peerDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/compat/src/audit/babel-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,16 @@ function _inExportDeclarationContext(path: NodePath): boolean {
case 'ObjectPattern':
case 'ArrayPattern':
case 'RestElement':
return inExportDeclarationContext(path.parentPath);
return inExportDeclarationContext(path.parentPath!);
case 'VariableDeclarator':
return parent.id === path.node && inExportDeclarationContext(path.parentPath);
return parent.id === path.node && inExportDeclarationContext(path.parentPath!);
case 'ObjectProperty':
return parent.value === path.node && inExportDeclarationContext(path.parentPath);
return parent.value === path.node && inExportDeclarationContext(path.parentPath!);
case 'AssignmentPattern':
return parent.left === path.node && inExportDeclarationContext(path.parentPath);
return parent.left === path.node && inExportDeclarationContext(path.parentPath!);
case 'FunctionDeclaration':
case 'ClassDeclaration':
return parent.id === path.node && inExportDeclarationContext(path.parentPath);
return parent.id === path.node && inExportDeclarationContext(path.parentPath!);
default:
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/babel-plugin-adjust-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function main(babel: typeof Babel) {
};

function addExtraImports(t: BabelTypes, path: NodePath<t.Program>, config: InternalConfig) {
let filename: string = path.hub.file.opts.filename;
let filename: string = (path.hub as any).file.opts.filename;
let entry = config.extraImports[filename];
let adder = new ImportUtil(t, path);
if (entry) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/modules-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mergeTrees from 'broccoli-merge-trees';
// output in a `modules` folder. This strips that level off if it exists,
// without discarding any other content that was not inside `modules`.

export default function modulesCompat(tree: Node) {
export default function modulesCompat(tree: Node): Node {
return mergeTrees([
buildFunnel(tree, { exclude: ['modules'] }),
buildFunnel(tree, { srcDir: 'modules', allowEmpty: true }),
Expand Down
5 changes: 4 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
"@embroider/sample-transforms": "0.0.0",
"@embroider/test-support": "0.36.0",
"@glimmer/syntax": "^0.84.2",
"@glint/template": "^1.0.0",
"@types/babel__core": "^7.1.14",
"@types/babel__traverse": "^7.18.5",
"@types/debug": "^4.1.5",
"@types/filesize": "^4.0.0",
"@types/fs-extra": "^9.0.12",
"@types/jsdom": "^16.2.11",
"@types/js-string-escape": "^1.0.0",
"@types/lodash": "^4.14.170",
"@types/node": "^15.12.2",
"@types/resolve": "^1.20.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/measure-concat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SourceMapConcat from 'fast-sourcemap-concat';
import { join } from 'path';
import { statSync } from 'fs';
import filesize from 'filesize';
import { filesize } from 'filesize';

export default class MeasureConcat {
stats: { [filename: string]: number } = {};
Expand All @@ -19,7 +19,7 @@ export default class MeasureConcat {
console.log(
Object.entries(this.stats)
.sort((a, b) => b[1] - a[1])
.map(([name, bytes]) => ` ${name}: ${filesize(bytes)}`)
.map(([name, bytes]) => ` ${name}: ${filesize(bytes, {})}`)
.join('\n')
);
return await this.concat.end();
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Note that these can be used in combination - e.g. if you run tests in the produc
If you are using [Glint](https://typed-ember.gitbook.io/glint/) and `environment-ember-loose`, you can add all the macros to your app at once by adding
```ts
import type { EmbroiderMacrosRegistry } from "@embroider/macros/src/template-registry";
import type { EmbroiderMacrosRegistry } from "@embroider/macros";
```
to your app's e.g. `types/glint.d.ts` file, and making sure your registry extends from EmbroiderMacrosRegistry:
Expand Down
13 changes: 12 additions & 1 deletion packages/macros/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,28 @@
"@babel/traverse": "^7.14.5",
"@embroider/core": "2.1.1",
"@embroider/test-support": "0.36.0",
"@glint/template": "^1.0.0",
"@types/babel__core": "^7.1.14",
"@types/babel__generator": "^7.6.2",
"@types/babel__template": "^7.4.0",
"@types/babel__traverse": "^7.18.5",
"@types/lodash": "^4.14.170",
"@types/node": "^15.12.2",
"@types/resolve": "^1.20.0",
"@types/semver": "^7.3.6",
"babel-plugin-ember-template-compilation": "^2.0.0",
"code-equality-assertions": "^0.9.0",
"scenario-tester": "^2.0.1",
"scenario-tester": "^2.1.2",
"typescript": "*"
},
"peerDependencies": {
"@glint/template": "^1.0.0"
},
"peerDependenciesMeta": {
"@glint/template": {
"optional": true
}
},
"engines": {
"node": "12.* || 14.* || >= 16"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/src/babel/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function collapse(path: NodePath, config: any) {
let evaluator = new Evaluator({ knownPaths: new Map([[path, { confident: true, value: config }]]) });

while (true) {
let parentPath = path.parentPath;
let parentPath = path.parentPath!;
let result = evaluator.evaluate(parentPath);
if (!result.confident || parentPath.isAssignmentExpression()) {
return { path, config: (evaluator.evaluate(path) as ConfidentResult).value };
Expand Down
2 changes: 1 addition & 1 deletion packages/macros/src/babel/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function initState(t: typeof Babel.types, path: NodePath<Babel.types.Prog
state.removed = new Set();
state.calledIdentifiers = new Set();
state.packageCache = PackageCache.shared('embroider-stage3', state.opts.appPackageRoot);
state.sourceFile = state.opts.owningPackageRoot || path.hub.file.opts.filename;
state.sourceFile = state.opts.owningPackageRoot || (path.hub as any).file.opts.filename;
state.pathToOurAddon = pathToAddon;
state.owningPackage = owningPackage;
state.cloneDeep = cloneDeep;
Expand Down
Loading

0 comments on commit 5877484

Please sign in to comment.