Skip to content

Commit 9e562d8

Browse files
Updates to SPC Build process
1 parent 838a3c0 commit 9e562d8

File tree

15 files changed

+368
-10
lines changed

15 files changed

+368
-10
lines changed

.github/workflows/spc-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish @nhs-fdp/spc
1+
name: Publish @nhsdigital/spc
22

33
on:
44
push:
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
node-version: 22.x
2525
registry-url: 'https://npm.pkg.github.com'
26-
scope: '@fergusbisset'
26+
scope: '@nhsdigital'
2727

2828
- name: Install dependencies
2929
run: npm ci
@@ -43,7 +43,7 @@ jobs:
4343
run: npm run build
4444
working-directory: packages/nhs-fdp-spc
4545

46-
- name: Publish @nhs-fdp/spc to GitHub Packages (alpha tag)
46+
- name: Publish @nhsdigital/spc to GitHub Packages (alpha tag)
4747
run: npm publish --tag alpha
4848
working-directory: packages/nhs-fdp-spc
4949
env:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Use Node.js 22.x
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22.x
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Exports check
27+
run: npm run exports:check
28+
29+
- name: Build
30+
run: npm run build
31+
32+
- name: Dry-run pack
33+
run: npm pack --dry-run
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish @nhsdigital/spc
2+
3+
on:
4+
push:
5+
tags:
6+
- 'spc-v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Use Node.js 22.x
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22.x
24+
registry-url: 'https://npm.pkg.github.com'
25+
scope: '@nhsdigital'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Verify tag matches package version
31+
run: |
32+
PKG_VERSION=$(node -p "require('./package.json').version")
33+
TAG_VERSION=${GITHUB_REF_NAME#spc-v}
34+
echo "Package version: $PKG_VERSION"
35+
echo "Tag version: $TAG_VERSION"
36+
test "$PKG_VERSION" = "$TAG_VERSION"
37+
38+
- name: Build SPC package
39+
run: npm run build
40+
41+
- name: Publish @nhsdigital/spc (alpha tag)
42+
run: npm publish --tag alpha
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { defineConfig, Plugin } from 'vite';
2+
import react from '@vitejs/plugin-react';
3+
import { resolve } from 'path';
4+
import { existsSync } from 'fs';
5+
import dts from 'vite-plugin-dts';
6+
7+
// Ignore SCSS during JS lib build
8+
const ignoreScssPlugin = (): Plugin => ({
9+
name: 'spc-ignore-scss',
10+
load(id) {
11+
if (id.endsWith('.scss')) return { code: '' };
12+
}
13+
});
14+
15+
// Resolve '@' alias: in monorepo use root src; in split use local src
16+
const monorepoSrc = resolve(__dirname, '../../../src');
17+
const localSrc = resolve(__dirname, '../src');
18+
const atAlias = existsSync(monorepoSrc) ? monorepoSrc : localSrc;
19+
20+
export default defineConfig({
21+
plugins: [
22+
ignoreScssPlugin(),
23+
react({ jsxRuntime: 'classic' }),
24+
dts({
25+
entryRoot: resolve(__dirname, '../src'),
26+
outDir: resolve(__dirname, '../dist'),
27+
tsconfigPath: resolve(__dirname, '../tsconfig.json'),
28+
copyDtsFiles: true
29+
})
30+
],
31+
resolve: {
32+
alias: {
33+
'@': atAlias
34+
}
35+
},
36+
build: {
37+
lib: {
38+
entry: {
39+
index: resolve(__dirname, '../src/index.ts'),
40+
engine: resolve(__dirname, '../src/engine/index.ts'),
41+
icons: resolve(__dirname, '../src/icons/index.ts')
42+
},
43+
formats: ['es'],
44+
fileName: (_format, entryName) => {
45+
if (entryName === 'index') return 'index.esm.js';
46+
return `${entryName}/index.js`;
47+
}
48+
},
49+
rollupOptions: {
50+
external: [
51+
'react',
52+
'react-dom',
53+
'react/jsx-runtime',
54+
'react/jsx-dev-runtime'
55+
]
56+
},
57+
sourcemap: true,
58+
copyPublicDir: false,
59+
outDir: resolve(__dirname, '../dist'),
60+
emptyOutDir: true
61+
}
62+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'vite';
2+
import { resolve } from 'path';
3+
4+
export default defineConfig({
5+
build: {
6+
lib: {
7+
entry: resolve(__dirname, '../src/styles/spc.scss'),
8+
formats: ['es'],
9+
fileName: () => 'spc'
10+
},
11+
rollupOptions: {
12+
output: {
13+
assetFileNames: (assetInfo) => {
14+
if (assetInfo.name && assetInfo.name.endsWith('.css')) return 'spc.css';
15+
return assetInfo.name || '[name]';
16+
}
17+
}
18+
},
19+
sourcemap: true,
20+
copyPublicDir: false,
21+
outDir: resolve(__dirname, '../dist'),
22+
emptyOutDir: false,
23+
cssCodeSplit: false,
24+
minify: false
25+
}
26+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Engine entry for @nhs-fdp/spc/engine */
2+
export * from '../../../../src/components/DataVisualisation/charts/SPC/engine';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Icons entry for @nhs-fdp/spc/icons */
2+
export * from '../../../../src/components/DataVisualisation/charts/SPC/icons';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Public entry for @nhsdigital/spc.
3+
* Re-exports the existing SPC barrel from the monorepo source (not yet vendored).
4+
*/
5+
export * from '../../../src/components/DataVisualisation/charts/SPC';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Temporary module shims to allow cross-package re-exports during subrepo setup.
2+
declare module '@ds/components/DataVisualisation/charts/SPC';
3+
declare module '@ds/components/DataVisualisation/charts/SPC/engine';
4+
declare module '@ds/components/DataVisualisation/charts/SPC/icons';

packages/nhs-fdp-spc/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@fergusbisset/spc",
2+
"name": "@nhsdigital/spc",
33
"version": "0.0.1-alpha.0",
44
"description": "Statistical Process Control (SPC) components and engine for the NHS FDP Design System",
55
"type": "module",
@@ -43,8 +43,8 @@
4343
},
4444
"dependencies": {},
4545
"scripts": {
46-
"build": "vite build --config ../../config/vite.spc.config.ts && vite build --config ../../config/vite.spc.css.config.ts",
47-
"exports:check": "node ../../scripts/spc-export-check.cjs",
46+
"build": "node ./scripts/build-spc.mjs",
47+
"exports:check": "node ./scripts/spc-export-check.cjs",
4848
"prepublishOnly": "npm run exports:check && npm run build",
4949
"test": "vitest run --dir ./tests"
5050
}

0 commit comments

Comments
 (0)