Skip to content

Commit 1763058

Browse files
Update @manypkg/* packages to be ESM only (#242)
* chore: upgrade preconstruct-cli, p-limit, and prepare tsconfig changes * chore: upgrade the package.json files to use ESM + exports * chore: add .node-version file for node 22 * chore: upgrade relative imports, remove unused vars, fix many-pkg/cli bin * fix: no need for brackets * fix: run prettier across changes :) * fix: use node 22 in CI * chore: changeset * Merge pull request #1 from Andarist/esm-only-fixes fix stuff * fix syntax err (#2) * Fix CI checks (#3) * Fix TS issues * fix knip * fix tests * bump changes to major Co-authored-by: Mateusz Burzyński <[email protected]> * Make CI setup reusable --------- Co-authored-by: Mateusz Burzyński <[email protected]>
1 parent 9a1546c commit 1763058

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+746
-491
lines changed

.changeset/mighty-frogs-fail.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@manypkg/cli": minor
3+
"@manypkg/find-root": major
4+
"@manypkg/get-packages": major
5+
"@manypkg/tools": major
6+
---
7+
8+
This package is now published as a [pure ESM package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).

.github/actions/ci-setup/action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Setup CI
2+
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Setup Node.js
7+
uses: actions/setup-node@v4
8+
with:
9+
node-version-file: ".node-version"
10+
11+
- name: Install dependencies
12+
shell: bash
13+
run: yarn install --frozen-lockfile

.github/workflows/changeset-release.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,11 @@ jobs:
1010
name: Release
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Checkout Repo
14-
uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1514
with:
1615
fetch-depth: 0
16+
- uses: ./.github/actions/ci-setup
1717

18-
- name: Set Node.js 18.x
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: 18.x
22-
23-
- name: Install Yarn
24-
run: npm install --global yarn
25-
26-
- name: Install Dependencies
27-
run: yarn
2818
- run: git branch -a
2919

3020
- name: "Create Pull Request or Publish to npm"

.github/workflows/main.yml

+8-36
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ jobs:
1111
name: Tests
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
15-
16-
- name: Set Node.js 18.x
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: 18.x
20-
21-
- name: Install Dependencies
22-
run: yarn
14+
- uses: actions/checkout@v4
15+
- uses: ./.github/actions/ci-setup
2316

2417
- name: Run Tests
2518
run: yarn test
@@ -28,15 +21,8 @@ jobs:
2821
name: TypeScript
2922
runs-on: ubuntu-latest
3023
steps:
31-
- uses: actions/checkout@v3
32-
33-
- name: Set Node.js 18.x
34-
uses: actions/setup-node@v3
35-
with:
36-
node-version: 18.x
37-
38-
- name: Install Dependencies
39-
run: yarn
24+
- uses: actions/checkout@v4
25+
- uses: ./.github/actions/ci-setup
4026

4127
- name: Check Types
4228
run: yarn tsc
@@ -45,15 +31,8 @@ jobs:
4531
name: Formatting
4632
runs-on: ubuntu-latest
4733
steps:
48-
- uses: actions/checkout@v3
49-
50-
- name: Set Node.js 18.x
51-
uses: actions/setup-node@v3
52-
with:
53-
node-version: 18.x
54-
55-
- name: Install Dependencies
56-
run: yarn
34+
- uses: actions/checkout@v4
35+
- uses: ./.github/actions/ci-setup
5736

5837
- name: Check Formatting
5938
run: yarn format:check
@@ -62,15 +41,8 @@ jobs:
6241
name: Knip
6342
runs-on: ubuntu-latest
6443
steps:
65-
- uses: actions/checkout@v3
66-
67-
- name: Set Node.js 18.x
68-
uses: actions/setup-node@v3
69-
with:
70-
node-version: 18.x
71-
72-
- name: Install Dependencies
73-
run: yarn
44+
- uses: actions/checkout@v4
45+
- uses: ./.github/actions/ci-setup
7446

7547
- name: Check Knip
7648
run: yarn knip

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.14.0

knip.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ignoreWorkspaces": ["test-gatsby", "packages/gatsby-source-workspace"],
44
"workspaces": {
55
".": {
6-
"ignoreBinaries": ["gatsby", "manypkg"]
6+
"ignoreBinaries": ["gatsby", "packages/cli/bin.js"]
77
}
88
},
99
"ignore": ["__fixtures__/**"]

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"scripts": {
1111
"format": "prettier --write .",
1212
"format:check": "prettier --check .",
13-
"postinstall": "preconstruct dev && manypkg check",
13+
"postinstall": "preconstruct dev && NODE_OPTIONS=--experimental-strip-types packages/cli/bin.js check",
1414
"knip": "knip",
1515
"release": "preconstruct build && changeset publish",
1616
"test": "jest",
@@ -29,7 +29,7 @@
2929
"@babel/preset-typescript": "^7.18.6",
3030
"@changesets/changelog-github": "^0.4.8",
3131
"@changesets/cli": "^2.26.0",
32-
"@preconstruct/cli": "^2.8.9",
32+
"@preconstruct/cli": "^2.8.12",
3333
"@types/jest": "^29.2.4",
3434
"@types/normalize-path": "^3.0.0",
3535
"@types/parse-github-url": "^1.0.0",
@@ -46,8 +46,13 @@
4646
"packages": [
4747
"packages/!(gatsby)*"
4848
],
49+
"exports": {
50+
"importConditionDefaultExport": "default"
51+
},
4952
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
50-
"keepDynamicImportAsDynamicImportInCommonJS": true
53+
"distInRoot": true,
54+
"importsConditions": true,
55+
"typeModule": true
5156
}
5257
}
5358
}

packages/cli/bin.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/usr/bin/env node
2-
"use strict";
3-
4-
require(".");
2+
import "@manypkg/cli";

packages/cli/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
"directory": "packages/cli"
88
},
99
"license": "MIT",
10-
"main": "dist/manypkg-cli.cjs.js",
11-
"module": "dist/manypkg-cli.esm.js",
10+
"type": "module",
11+
"exports": {
12+
".": "./dist/manypkg-cli.js",
13+
"./package.json": "./package.json"
14+
},
1215
"bin": {
1316
"manypkg": "./bin.js"
1417
},
1518
"dependencies": {
1619
"@manypkg/get-packages": "^2.2.1",
1720
"detect-indent": "^6.0.0",
1821
"normalize-path": "^3.0.0",
19-
"p-limit": "^2.2.1",
22+
"p-limit": "^6.2.0",
2023
"package-json": "^10.0.1",
2124
"parse-github-url": "^1.0.2",
2225
"picocolors": "^1.1.0",

packages/cli/src/checks/EXTERNAL_MISMATCH.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {
22
makeCheck,
33
getMostCommonRangeMap,
44
NORMAL_DEPENDENCY_TYPES,
5-
} from "./utils";
6-
import { Package } from "@manypkg/get-packages";
5+
} from "./utils.ts";
6+
import type { Package } from "@manypkg/get-packages";
77
import { validRange } from "semver";
88

99
type ErrorType = {

packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import parseGithubUrl from "parse-github-url";
22
import normalizePath from "normalize-path";
3-
import { Package } from "@manypkg/get-packages";
3+
import type { Package } from "@manypkg/get-packages";
44

5-
import { makeCheck } from "./utils";
5+
import { makeCheck } from "./utils.ts";
66

77
type ErrorType = {
88
type: "INCORRECT_REPOSITORY_FIELD";

packages/cli/src/checks/INTERNAL_MISMATCH.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {
22
makeCheck,
33
NORMAL_DEPENDENCY_TYPES,
44
versionRangeToRangeType,
5-
} from "./utils";
5+
} from "./utils.ts";
66
import semver from "semver";
7-
import { Package } from "@manypkg/get-packages";
7+
import type { Package } from "@manypkg/get-packages";
88

99
export type ErrorType = {
1010
type: "INTERNAL_MISMATCH";

packages/cli/src/checks/INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { makeCheck, getMostCommonRangeMap } from "./utils";
2-
import { Package } from "@manypkg/get-packages";
1+
import { makeCheck, getMostCommonRangeMap } from "./utils.ts";
2+
import type { Package } from "@manypkg/get-packages";
33
import { upperBoundOfRangeAWithinBoundsOfB } from "sembear";
44
import semver from "semver";
55

packages/cli/src/checks/INVALID_PACKAGE_NAME.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Package } from "@manypkg/get-packages";
1+
import type { Package } from "@manypkg/get-packages";
2+
import { makeCheck } from "./utils.ts";
23
import validateNpmPackageName from "validate-npm-package-name";
3-
import { makeCheck } from "./utils";
44

55
type ErrorType = {
66
type: "INVALID_PACKAGE_NAME";

packages/cli/src/checks/MULTIPLE_DEPENDENCY_TYPES.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { makeCheck } from "./utils";
2-
import { Package } from "@manypkg/get-packages";
1+
import { makeCheck } from "./utils.ts";
2+
import type { Package } from "@manypkg/get-packages";
33

44
type ErrorType = {
55
type: "MULTIPLE_DEPENDENCY_TYPES";

packages/cli/src/checks/ROOT_HAS_PROD_DEPENDENCIES.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { makeCheck, sortObject } from "./utils";
1+
import { makeCheck, sortObject } from "./utils.ts";
22
import pc from "picocolors";
3-
import { Package } from "@manypkg/get-packages";
3+
import type { Package } from "@manypkg/get-packages";
44

55
type ErrorType = {
66
type: "ROOT_HAS_PROD_DEPENDENCIES";

packages/cli/src/checks/UNSORTED_DEPENDENCIES.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { makeCheck, DEPENDENCY_TYPES, sortDeps, isArrayEqual } from "./utils";
2-
import { Package } from "@manypkg/get-packages";
1+
import {
2+
makeCheck,
3+
DEPENDENCY_TYPES,
4+
sortDeps,
5+
isArrayEqual,
6+
} from "./utils.ts";
7+
import type { Package } from "@manypkg/get-packages";
38

49
type ErrorType = {
510
type: "UNSORTED_DEPENDENCIES";

packages/cli/src/checks/WORKSPACE_REQUIRED.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { makeCheck, NORMAL_DEPENDENCY_TYPES } from "./utils";
2-
import { Package } from "@manypkg/get-packages";
1+
import { makeCheck, NORMAL_DEPENDENCY_TYPES } from "./utils.ts";
2+
import type { Package } from "@manypkg/get-packages";
33

44
type ErrorType = {
55
type: "WORKSPACE_REQUIRED";

packages/cli/src/checks/__tests__/EXTERNAL_MISMATCH.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import internalMismatch from "../EXTERNAL_MISMATCH";
2-
import { getWS, getFakeWS, getRootWS } from "../../test-helpers";
1+
import internalMismatch from "../EXTERNAL_MISMATCH.ts";
2+
import { getWS, getFakeWS, getRootWS } from "../../test-helpers.ts";
33

44
let rootWorkspace = getRootWS();
55

packages/cli/src/checks/__tests__/INCORRECT_REPOSITORY_FIELD.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import path from "path";
2-
import check from "../INCORRECT_REPOSITORY_FIELD";
3-
import { getWS, getFakeWS, getFakeString, getRootWS } from "../../test-helpers";
1+
import {
2+
getFakeString,
3+
getFakeWS,
4+
getRootWS,
5+
getWS,
6+
} from "../../test-helpers.ts";
7+
import check from "../INCORRECT_REPOSITORY_FIELD.ts";
48

59
describe("incorrect repository field", () => {
610
describe("github", () => {

packages/cli/src/checks/__tests__/INTERNAL_MISMATCH.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import makeCheck, { ErrorType } from "../INTERNAL_MISMATCH";
2-
import { getWS, getFakeWS, getRootWS } from "../../test-helpers";
1+
import { getFakeWS, getRootWS, getWS } from "../../test-helpers.ts";
2+
import makeCheck, { ErrorType } from "../INTERNAL_MISMATCH.ts";
33

44
let rootWorkspace = getRootWS();
55

packages/cli/src/checks/__tests__/INVALID_DEV_AND_PEER_DEPENDENCY.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import makeCheck from "../INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP";
2-
import { getWS, getFakeWS, getRootWS } from "../../test-helpers";
1+
import { getFakeWS, getRootWS, getWS } from "../../test-helpers.ts";
2+
import makeCheck from "../INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP.ts";
33

44
let rootWorkspace = getRootWS();
55

packages/cli/src/checks/__tests__/WORKSPACE_REQUIRED.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getWS, getFakeWS, getRootWS } from "../../test-helpers";
2-
import makeCheck from "../WORKSPACE_REQUIRED";
1+
import { getFakeWS, getRootWS, getWS } from "../../test-helpers.ts";
2+
import makeCheck from "../WORKSPACE_REQUIRED.ts";
33
let rootWorkspace = getRootWS();
44

55
test("should not error if not using workspaceProtocol: require", () => {

packages/cli/src/checks/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import EXTERNAL_MISMATCH from "./EXTERNAL_MISMATCH";
2-
import INTERNAL_MISMATCH from "./INTERNAL_MISMATCH";
3-
import INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP from "./INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP";
4-
import INVALID_PACKAGE_NAME from "./INVALID_PACKAGE_NAME";
5-
import MULTIPLE_DEPENDENCY_TYPES from "./MULTIPLE_DEPENDENCY_TYPES";
6-
import ROOT_HAS_PROD_DEPENDENCIES from "./ROOT_HAS_PROD_DEPENDENCIES";
7-
import UNSORTED_DEPENDENCIES from "./UNSORTED_DEPENDENCIES";
8-
import INCORRECT_REPOSITORY_FIELD from "./INCORRECT_REPOSITORY_FIELD";
9-
import WORKSPACE_REQUIRED from "./WORKSPACE_REQUIRED";
1+
import EXTERNAL_MISMATCH from "./EXTERNAL_MISMATCH.ts";
2+
import INTERNAL_MISMATCH from "./INTERNAL_MISMATCH.ts";
3+
import INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP from "./INVALID_DEV_AND_PEER_DEPENDENCY_RELATIONSHIP.ts";
4+
import INVALID_PACKAGE_NAME from "./INVALID_PACKAGE_NAME.ts";
5+
import MULTIPLE_DEPENDENCY_TYPES from "./MULTIPLE_DEPENDENCY_TYPES.ts";
6+
import ROOT_HAS_PROD_DEPENDENCIES from "./ROOT_HAS_PROD_DEPENDENCIES.ts";
7+
import UNSORTED_DEPENDENCIES from "./UNSORTED_DEPENDENCIES.ts";
8+
import INCORRECT_REPOSITORY_FIELD from "./INCORRECT_REPOSITORY_FIELD.ts";
9+
import WORKSPACE_REQUIRED from "./WORKSPACE_REQUIRED.ts";
1010

1111
export let checks = {
1212
EXTERNAL_MISMATCH,

packages/cli/src/checks/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Package } from "@manypkg/get-packages";
1+
import type { Package } from "@manypkg/get-packages";
22
import * as semver from "semver";
33
import { highest } from "sembear";
44

packages/cli/src/index.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import path from "path";
2-
import * as logger from "./logger";
3-
import { getPackages, Packages, Package } from "@manypkg/get-packages";
4-
import { Options } from "./checks/utils";
5-
import { checks } from "./checks";
6-
import { ExitError } from "./errors";
7-
import { writePackage, install } from "./utils";
8-
import { runCmd } from "./run";
9-
import { upgradeDependency } from "./upgrade";
10-
import { npmTagAll } from "./npm-tag";
1+
import path from "node:path";
2+
import * as logger from "./logger.ts";
3+
import {
4+
getPackages,
5+
type Packages,
6+
type Package,
7+
} from "@manypkg/get-packages";
8+
import type { Options } from "./checks/utils.ts";
9+
import { checks } from "./checks/index.ts";
10+
import { ExitError } from "./errors.ts";
11+
import { writePackage, install } from "./utils.ts";
12+
import { runCmd } from "./run.ts";
13+
import { upgradeDependency } from "./upgrade.ts";
14+
import { npmTagAll } from "./npm-tag.ts";
1115
import { exec } from "tinyexec";
1216
import pLimit from "p-limit";
1317

packages/cli/src/logger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pc from "picocolors";
2-
import util from "util";
2+
import util from "node:util";
33

44
function format(
55
args: Array<any>,

0 commit comments

Comments
 (0)