Skip to content

Commit 85ddc39

Browse files
committed
build: don't build project in postinstall script
The CLI currently runs `npm run build` in a post-install script. Many of commands in the CLI implicitly depend on this behavior, which is unnecessarily complicated. This post-install script conflicts with the user-facing post-install script, which means we need to do a little pre- publish post-install script juggling to ensure that the end user runs the correct script after installing the CLI. This change removes the post-install script in favor of explicitly building the CLI before e.g. CI steps that require a built CLI. Partial un-reversion of #7069, which was reverted in #7085.
1 parent 1492b4f commit 85ddc39

File tree

10 files changed

+69
-71
lines changed

10 files changed

+69
-71
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ jobs:
4545
- name: Install dependencies
4646
run: npm ci --no-audit
4747

48-
- run: npm run e2e
48+
- name: Build project
49+
run: npm run build
50+
51+
- name: Run E2E tests
52+
run: npm run e2e
4953

5054
- name: Notify Slack
5155
uses: 8398a7/action-slack@v3
@@ -97,7 +101,11 @@ jobs:
97101
- name: Install dependencies
98102
run: npm ci --no-audit
99103

100-
- run: npm run e2e
104+
- name: Build project
105+
run: npm run build
106+
107+
- name: Run E2E tests
108+
run: npm run e2e
101109

102110
- name: Notify Slack
103111
uses: 8398a7/action-slack@v3

.github/workflows/integration-tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ jobs:
7474
run: npm ci --no-audit
7575
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
7676

77+
- name: Build project
78+
run: npm run build
79+
7780
- name: Generate self-signed certificates
7881
run: npm run certs
7982
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
@@ -186,6 +189,9 @@ jobs:
186189
run: npm ci --no-audit
187190
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
188191

192+
- name: Build project
193+
run: npm run build
194+
189195
- name: Generate self-signed certificates
190196
run: npm run certs
191197
if: '${{!steps.release-check.outputs.IS_RELEASE}}'

.github/workflows/pre-release-sha.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install core dependencies
3030
run: npm ci --no-audit
3131

32-
- name: Build
32+
- name: Build project
3333
run: npm run build
3434

3535
- name: Configure Git user

.github/workflows/pre-release.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- name: Install core dependencies
2424
run: npm ci --no-audit
2525

26+
- name: Build project
27+
run: npm run build
28+
2629
- name: Extract tag and version
2730
id: extract
2831
run: |-
@@ -38,11 +41,10 @@ jobs:
3841
echo tag=${{ steps.extract.outputs.tag }}
3942
echo version=${{ steps.extract.outputs.version }}
4043
41-
- name: Setup git user
42-
run: git config --global user.name github-actions
43-
44-
- name: Setup git email
45-
run: git config --global user.email [email protected]
44+
- name: Configure Git user
45+
run: |
46+
git config --global user.name "Netlify"
47+
git config --global user.email "82042599+token-generator-app[bot]@users.noreply.github.com"
4648
4749
- name: Run npm version
4850
run: npm version ${{ steps.extract.outputs.version }}-${{ steps.extract.outputs.tag }} --allow-same-version

.github/workflows/release-please.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- name: Install core dependencies
4444
run: npm ci --no-audit
4545

46-
- run: npm publish --provenance
46+
- name: Publish package
47+
run: npm publish --provenance
4748
env:
4849
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/unit-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
run: npm ci --no-audit
4646
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
4747

48+
- name: Build project
49+
run: npm run build
50+
if: '${{!steps.release-check.outputs.IS_RELEASE}}'
51+
4852
- name: Run unit tests
4953
uses: nick-fields/retry@v3
5054
with:

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Run:
3333

3434
```bash
3535
npm install
36+
npm run build
3637
```
3738

3839
Tests are run with:
@@ -67,15 +68,14 @@ npm run watch
6768

6869
Make sure everything is correctly set up by running those tests first.
6970

70-
ESLint and Prettier have performed automatically on `git push`. However, we recommend you set up your IDE or text editor
71-
to run ESLint and Prettier automatically on file save. Otherwise, you should run them manually using:
71+
We recommend you set up your IDE or text editor to run ESLint and Prettier automatically on file save. Otherwise, you
72+
can run them manually using:
7273

7374
```bash
7475
npm run format
76+
npm run lint:fix
7577
```
7678

77-
Alternatively, you can set up your IDE to integrate with Prettier and ESLint for JavaScript and Markdown files.
78-
7979
To run the CLI locally:
8080

8181
```bash

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@
5555
"e2e": "node ./tools/e2e/run.js",
5656
"docs": "npm run --prefix=site build",
5757
"watch": "c8 --reporter=lcov vitest --watch",
58-
"postinstall-pack": "node ./scripts/postinstall.js",
59-
"postinstall": "npm run build && node ./scripts/postinstall.js",
60-
"prepublishOnly": "node ./scripts/prepare-for-publish.js",
58+
"postinstall": "node ./scripts/postinstall.js",
59+
"prepublishOnly": "npm shrinkwrap",
6160
"certs": "openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj \"/CN=localhost\" -extensions EXT -config certconf",
6261
"typecheck": "tsc",
6362
"typecheck:watch": "tsc --watch"

scripts/postinstall.js

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import process from 'process'
1+
/*
2+
* This script runs after an end user installs the CLI. It installs command-line completion, prints
3+
* a welcome message, etc.
4+
*/
5+
6+
import fs from 'node:fs/promises'
7+
import path from 'node:path'
8+
import { fileURLToPath } from 'node:url'
9+
import process from 'node:process'
210
// eslint-disable-next-line no-restricted-imports
311
import chalk from 'chalk'
412

5-
import { createMainCommand } from '../dist/commands/index.js'
6-
import { generateAutocompletion } from '../dist/lib/completion/index.js'
13+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
714

8-
const id = (message) => message
15+
const identity = (message) => message
916

1017
/**
1118
*
@@ -14,7 +21,7 @@ const id = (message) => message
1421
* @returns
1522
*/
1623
const format = (message, styles) => {
17-
let func = id
24+
let func = identity
1825
try {
1926
func = chalk
2027
styles.forEach((style) => {
@@ -25,6 +32,9 @@ const format = (message, styles) => {
2532
}
2633

2734
const postInstall = async () => {
35+
const { createMainCommand } = await import('../dist/commands/index.js')
36+
const { generateAutocompletion } = await import('../dist/lib/completion/index.js')
37+
2838
// yarn plug and play seems to have an issue with reading an esm file by building up the cache.
2939
// as yarn pnp analyzes everything inside the postinstall
3040
// yarn pnp executes it out of a .yarn folder .yarn/unplugged/netlify-cli-file-fb026a3a6d/node_modules/netlify-cli/scripts/postinstall.js
@@ -56,4 +66,21 @@ const postInstall = async () => {
5666
console.log('')
5767
}
5868

59-
await postInstall()
69+
const main = async () => {
70+
// Check if this post-install script is being run by an end user installation
71+
// (`npm install [-g] netlify-cli`) or during local development (`npm install`/`npm ci`)
72+
let isEndUserInstall = false
73+
try {
74+
await fs.stat(path.resolve(__dirname, '../.git'))
75+
} catch (err) {
76+
if (err.code === 'ENOENT') {
77+
isEndUserInstall = true
78+
}
79+
}
80+
81+
if (isEndUserInstall) {
82+
await postInstall()
83+
}
84+
}
85+
86+
await main()

scripts/prepare-for-publish.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)