Skip to content

Commit 20246a1

Browse files
committed
Chore: Distribution CI #181
1 parent ddb7d94 commit 20246a1

File tree

13 files changed

+159
-60
lines changed

13 files changed

+159
-60
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Setup
22
description: Node.js setup for CI/CD
33

4+
inputs:
5+
strict:
6+
description: Paths to cache
7+
required: false
8+
default: "true"
9+
410
runs:
511
using: composite
612
steps:
@@ -20,5 +26,11 @@ runs:
2026
${{ runner.os }}-yarn-
2127
2228
- name: Package Install
23-
run: yarn install --immutable
29+
run: |
30+
if [ "${{ inputs.strict }}" = "true" ]; then
31+
yarn install --immutable --check-resolutions --refresh-lockfile
32+
yarn constraints
33+
else
34+
yarn install
35+
fi
2436
shell: bash

.github/workflows/ci.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ jobs:
2020
skip_after_successful_duplicate: "true"
2121
paths_ignore: '["**/README.md"]'
2222

23+
checks:
24+
needs: pre_job
25+
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Setup
33+
uses: ./.github/actions/node-setup
34+
35+
- name: More setup cache
36+
uses: ./.github/actions/cache-dir
37+
with:
38+
key: checker
39+
40+
- name: Typechecker
41+
run: yarn build:type
42+
43+
- name: Lint & format
44+
run: |
45+
## Workflow lint
46+
yarn lint:action
47+
48+
## Require type build
49+
# https://typescript-eslint.io/getting-started/typed-linting/
50+
yarn lint
51+
2352
build:
2453
needs: pre_job
2554
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
@@ -31,14 +60,13 @@ jobs:
3160

3261
- name: Setup
3362
uses: ./.github/actions/node-setup
63+
with:
64+
strict: false
3465

3566
- name: More setup cache
3667
uses: ./.github/actions/cache-dir
3768
with:
3869
key: build-and-test
3970

40-
- name: Workflow lint
41-
run: yarn lint:action
42-
4371
- name: Test
44-
run: yarn test:all
72+
run: yarn test

.github/workflows/fast-forward.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ jobs:
117117
- name: Setup
118118
uses: ./.github/actions/node-setup
119119

120-
- name: More setup cache
121-
uses: ./.github/actions/cache-dir
122-
with:
123-
key: build-and-test
124-
125120
- name: Create Release Pull Request or Publish to npm
126121
id: changesets
127122
uses: changesets/action@v1
@@ -132,6 +127,7 @@ jobs:
132127
setupGitUser: true
133128
createGithubReleases: true
134129
env:
130+
PACKAGE_PUBLISH: "true"
135131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
136132
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
137133

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@
2424
"typescript",
2525
"typescriptreact",
2626
"vue"
27+
],
28+
"cSpell.words": [
29+
"codegen",
30+
"forallpackages",
31+
"mincho"
2732
]
2833
}

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ compressionLevel: mixed
66

77
enableGlobalCache: true
88

9+
enableHardenedMode: false
10+
911
globalFolder: ./.yarn/cache
1012

1113
nodeLinker: pnpm
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
export default {
22
$schema: "https://json.schemastore.org/prettierrc",
3-
parser: "typescript",
4-
trailingComma: "none",
53
tabWidth: 2,
6-
semi: true,
7-
bracketSpacing: true,
8-
arrowParens: "always"
4+
5+
overrides: [
6+
{
7+
files: [
8+
"*.js",
9+
"*.cjs",
10+
"*.mjs",
11+
"*.ts",
12+
"*.cts",
13+
"*.mts",
14+
"*.jsx",
15+
"*.tsx"
16+
],
17+
options: {
18+
trailingComma: "none",
19+
semi: true,
20+
bracketSpacing: true,
21+
arrowParens: "always"
22+
}
23+
}
24+
]
925
};

configs/vite-config-custom/index.js

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { readdirSync, renameSync } from "node:fs";
44
import { resolve, join } from "node:path";
5-
import { cwd } from "node:process";
5+
import { cwd, env } from "node:process";
66

77
import { initConfigBuilder, ViteEnv, PluginBuilder } from "vite-config-builder";
88
import { mergeConfig } from "vite";
@@ -35,46 +35,49 @@ function NodeBuilder(viteConfigEnv) {
3535
const outEsmDir = resolve(packageRoot, "dist", "esm");
3636
const outCjsDir = resolve(packageRoot, "dist", "cjs");
3737

38+
const isCI = isGithubCI();
3839
if (ViteEnv.isProd()) {
39-
plugins.add(
40-
// This is currently a proprietary implementation. You might also like to see
41-
// https://github.com/qmhc/vite-plugin-dts/issues/267
42-
dts({
43-
entryRoot,
44-
include: ["src"],
45-
outDir: outEsmDir,
46-
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json")
47-
}),
48-
dts({
49-
entryRoot,
50-
include: ["src"],
51-
outDir: outCjsDir,
52-
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json"),
53-
compilerOptions: {
54-
module: ModuleKind.CommonJS,
40+
if (!isCI) {
41+
plugins.add(
42+
// This is currently a proprietary implementation. You might also like to see
43+
// https://github.com/qmhc/vite-plugin-dts/issues/267
44+
dts({
45+
entryRoot,
46+
include: ["src"],
47+
outDir: outEsmDir,
48+
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json")
49+
}),
50+
dts({
51+
entryRoot,
52+
include: ["src"],
5553
outDir: outCjsDir,
56-
declarationDir: outCjsDir,
57-
tsBuildInfoFile: resolve(
58-
packageRoot,
59-
".cache",
60-
"typescript",
61-
"tsbuildinfo-cjs"
62-
)
63-
},
64-
afterBuild: () => {
65-
// Rename the CommonJS declaration file to .d.cts
66-
readdirSync(outCjsDir).forEach((file) => {
67-
if (file.endsWith(".d.ts")) {
68-
renameSync(
69-
join(outCjsDir, file),
70-
join(outCjsDir, file.replace(".d.ts", ".d.cts"))
71-
);
72-
}
73-
});
74-
}
75-
}),
76-
externalizeDeps()
77-
);
54+
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json"),
55+
compilerOptions: {
56+
module: ModuleKind.CommonJS,
57+
outDir: outCjsDir,
58+
declarationDir: outCjsDir,
59+
tsBuildInfoFile: resolve(
60+
packageRoot,
61+
".cache",
62+
"typescript",
63+
"tsbuildinfo-cjs"
64+
)
65+
},
66+
afterBuild: () => {
67+
// Rename the CommonJS declaration file to .d.cts
68+
readdirSync(outCjsDir).forEach((file) => {
69+
if (file.endsWith(".d.ts")) {
70+
renameSync(
71+
join(outCjsDir, file),
72+
join(outCjsDir, file.replace(".d.ts", ".d.cts"))
73+
);
74+
}
75+
});
76+
}
77+
})
78+
);
79+
}
80+
plugins.add(externalizeDeps());
7881
}
7982

8083
if (ViteEnv.isTest()) {
@@ -113,7 +116,7 @@ function NodeBuilder(viteConfigEnv) {
113116
entry: {
114117
index: entryFile
115118
},
116-
formats: ["es", "cjs"],
119+
formats: isCI ? ["es"] : ["es", "cjs"],
117120
fileName: (format, entryName) =>
118121
`${format === "es" ? "esm" : "cjs"}/${entryName}.${format === "es" ? "mjs" : "cjs"}`
119122
},
@@ -166,3 +169,14 @@ function initCommonBuilder(viteConfigEnv) {
166169
plugins
167170
};
168171
}
172+
173+
function isGithubCI() {
174+
if (env["PACKAGE_PUBLISH"] === "true") {
175+
return false;
176+
}
177+
178+
if (env["GITHUB_ACTIONS"] === "true") {
179+
return true;
180+
}
181+
return false;
182+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"clean": "yarn g:clean && yarn task clean",
1414
"build": "yarn task build",
1515
"build:type": "yarn tsc --build",
16-
"lint": "yarn lint:action && yarn task lint",
16+
"lint": "yarn task lint",
17+
"lint:action": "yarn run -T eslint '.github/**/*.{js,yaml,yml}' --cache --cache-location .cache/eslint_action",
1718
"fix": "yarn fix:action && yarn task fix",
1819
"fix:action": "yarn lint:action --fix",
1920
"check": "yarn task check",
@@ -24,7 +25,6 @@
2425
"test:all": "yarn task test:all",
2526
"coverage": "yarn task coverage",
2627
"coverage:all": "yarn task coverage:all",
27-
"lint:action": "yarn run -T eslint '.github/**/*.{js,yaml,yml}' --cache --cache-location .cache/eslint_action",
2828
"forallpackages": "yarn workspaces foreach -Aptv --no-private --verbose",
2929
"build:release": "yarn build && yarn forallpackages exec rimraf _release && yarn forallpackages pack && yarn forallpackages exec \"mkdir _release && tar zxvf package.tgz --directory _release && rm package.tgz\"",
3030
"changeset": "changeset",
@@ -42,6 +42,7 @@
4242
"g:check": "cd $INIT_CWD && yarn run -T tsc --noEmit",
4343
"g:check-trace": "cd $INIT_CWD && yarn run -T rimraf tsconfig.tsbuildinfo && yarn run -T tsc -p tsconfig.json --generateTrace traceDir && yarn run -T analyze-trace traceDir"
4444
},
45+
"prettier": "prettier-config-custom",
4546
"devDependencies": {
4647
"@changesets/changelog-github": "^0.5.1",
4748
"@changesets/cli": "^2.28.1",
@@ -57,9 +58,11 @@
5758
"eslint": "^9.24.0",
5859
"eslint-config-custom": "workspace:^",
5960
"prettier": "^3.5.3",
61+
"prettier-config-custom": "workspace:^",
6062
"prettier-eslint": "^16.3.0",
6163
"rimraf": "6.0.0",
6264
"terser": "^5.39.0",
65+
"tsconfig-custom": "workspace:^",
6366
"turbo": "^2.5.0",
6467
"typescript": "^5.8.3",
6568
"vite": "^6.2.6",

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
},
3535
{
3636
"path": "examples/react-swc"
37+
},
38+
{
39+
"path": "./tsconfig.node.json"
3740
}
3841
]
3942
}

tsconfig.node.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "tsconfig-custom/tsconfig.node.json",
3+
"compilerOptions": {
4+
"tsBuildInfoFile": "./.cache/typescript/tsbuildinfo-node",
5+
"outDir": "./.cache/tsbuild-node"
6+
},
7+
"include": [
8+
"yarn.config.cjs",
9+
"eslint.config.js",
10+
"vitest.workspace.ts"
11+
]
12+
}

0 commit comments

Comments
 (0)