From 374393dbfc5a4fe29e2cefe978563375070a09ce Mon Sep 17 00:00:00 2001 From: Rishabh Jain Date: Sun, 14 Jun 2026 11:53:41 +0530 Subject: [PATCH 1/8] feat(concerto): add tree-shakeable package entrypoints Signed-off-by: Rishabh Jain --- .github/workflows/build.yml | 52 +++++ e2e/.gitignore | 4 + e2e/package.json | 13 ++ e2e/playwright.config.ts | 30 +++ e2e/tests/browser-bundles.spec.ts | 86 +++++++ package-lock.json | 219 ++++++++++-------- package.json | 9 +- packages/concertino/package.json | 18 +- packages/concerto-analysis/package.json | 18 +- packages/concerto-core/package.json | 21 +- packages/concerto-core/src/datetimeutil.ts | 10 +- packages/concerto-core/src/dayjs-setup.ts | 28 +++ packages/concerto-core/src/factory.ts | 4 +- packages/concerto-core/src/model/typed.ts | 5 +- .../src/serializer/jsonpopulator.ts | 10 +- .../src/serializer/resourcevalidator.ts | 4 +- .../src/serializer/valuegenerator.ts | 4 +- packages/concerto-cto/package.json | 18 +- packages/concerto-linter/package.json | 18 +- packages/concerto-util/package.json | 18 +- packages/concerto-vocabulary/package.json | 16 +- scripts/build-esm.js | 62 +++++ 22 files changed, 523 insertions(+), 144 deletions(-) create mode 100644 e2e/.gitignore create mode 100644 e2e/package.json create mode 100644 e2e/playwright.config.ts create mode 100644 e2e/tests/browser-bundles.spec.ts create mode 100644 packages/concerto-core/src/dayjs-setup.ts create mode 100644 scripts/build-esm.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 583a48c786..f8793dbd8d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,6 +65,58 @@ jobs: parallel: true fail-on-error: false + e2e: + name: Browser E2E (Chromium) + runs-on: ubuntu-latest + needs: + - build + + steps: + - name: git checkout + uses: actions/checkout@v4 + + - name: Use Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build packages and browser bundles + run: npm run build + + - name: Get Playwright version + id: playwright-version + run: echo "version=$(node -p 'require(\"@playwright/test/package.json\").version')" >> "$GITHUB_OUTPUT" + + - name: Cache Playwright browsers + id: playwright-cache + uses: actions/cache@v4 + with: + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} + + - name: Install Playwright Chromium + if: steps.playwright-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps chromium + + - name: Install Playwright system deps only (cache hit) + if: steps.playwright-cache.outputs.cache-hit == 'true' + run: npx playwright install-deps chromium + + - name: Run browser e2e tests + run: npx playwright test --config e2e/playwright.config.ts --reporter=list + + - name: Upload Playwright report on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: e2e/playwright-report + retention-days: 7 + notify: needs: - build diff --git a/e2e/.gitignore b/e2e/.gitignore new file mode 100644 index 0000000000..e16c8f0203 --- /dev/null +++ b/e2e/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +test-results/ +playwright-report/ +playwright/.cache/ diff --git a/e2e/package.json b/e2e/package.json new file mode 100644 index 0000000000..bb886787f8 --- /dev/null +++ b/e2e/package.json @@ -0,0 +1,13 @@ +{ + "name": "concerto-e2e", + "version": "1.0.0", + "private": true, + "description": "End-to-end browser tests for Concerto web bundles.", + "scripts": { + "pretest:e2e": "npm --prefix .. run build", + "test:e2e": "playwright test" + }, + "devDependencies": { + "@playwright/test": "^1.60.0" + } +} diff --git a/e2e/playwright.config.ts b/e2e/playwright.config.ts new file mode 100644 index 0000000000..7ed127b7d5 --- /dev/null +++ b/e2e/playwright.config.ts @@ -0,0 +1,30 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests', + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 1 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'list', + use: { + trace: 'on-first-retry', + }, + projects: [ + { name: 'chromium', use: { ...devices['Desktop Chrome'] } }, + ], +}); diff --git a/e2e/tests/browser-bundles.spec.ts b/e2e/tests/browser-bundles.spec.ts new file mode 100644 index 0000000000..82eb64fce9 --- /dev/null +++ b/e2e/tests/browser-bundles.spec.ts @@ -0,0 +1,86 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { test, expect, Page } from '@playwright/test'; +import * as path from 'path'; + +const CTO_BUNDLE = path.resolve(__dirname, '../../packages/concerto-cto/dist/concerto-cto.js'); +const CORE_BUNDLE = path.resolve(__dirname, '../../packages/concerto-core/dist/concerto-core.js'); + +async function injectBundle(page: Page, bundlePath: string): Promise { + await page.goto('about:blank'); + await page.addScriptTag({ path: bundlePath }); +} + +test.describe('Concerto browser bundles', () => { + test('loads the CTO parser UMD bundle in Chromium', async ({ page }) => { + await injectBundle(page, CTO_BUNDLE); + + const parsed = await page.evaluate(() => { + const { Parser } = (window as any)['concerto-cto']; + const ast = Parser.parse('namespace org.acme.test@1.0.0\nconcept Person { o String name }'); + return { + namespace: ast.namespace, + declarationCount: ast.declarations.length, + }; + }); + + expect(parsed).toEqual({ + namespace: 'org.acme.test@1.0.0', + declarationCount: 1, + }); + }); + + test('loads the core UMD bundle and uses ModelManager in Chromium', async ({ page }) => { + await injectBundle(page, CORE_BUNDLE); + + const model = await page.evaluate(() => { + const { ModelManager } = (window as any)['concerto-core']; + const modelManager = new ModelManager(); + modelManager.addCTOModel( + 'namespace org.acme.browser@1.0.0\nasset Vehicle identified by vin { o String vin }', + 'vehicle.cto', + true + ); + const vehicle = modelManager.getType('org.acme.browser@1.0.0.Vehicle'); + return { + fqn: vehicle.getFullyQualifiedName(), + identifierFieldName: vehicle.getIdentifierFieldName(), + }; + }); + + expect(model).toEqual({ + fqn: 'org.acme.browser@1.0.0.Vehicle', + identifierFieldName: 'vin', + }); + }); + + test('keeps dayjs plugins available through the core bundle', async ({ page }) => { + await injectBundle(page, CORE_BUNDLE); + + const currentTime = await page.evaluate(() => { + const { DateTimeUtil } = (window as any)['concerto-core']; + const result = DateTimeUtil.setCurrentTime('2023-03-17T12:30:00.000Z', 0); + return { + iso: result.currentTime.toISOString(), + offset: result.utcOffset, + }; + }); + + expect(currentTime).toEqual({ + iso: '2023-03-17T12:30:00.000Z', + offset: 0, + }); + }); +}); diff --git a/package-lock.json b/package-lock.json index b11b5766a4..82a82f8160 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,13 +15,16 @@ "packages/concerto-util", "packages/concerto-vocabulary", "packages/concerto-linter", - "packages/concerto-linter/default-ruleset" + "packages/concerto-linter/default-ruleset", + "e2e" ], "devDependencies": { + "@playwright/test": "^1.60.0", "@types/path-browserify": "^1.0.3", "colors": "1.4.0", "coveralls-next": "^5.0.0", "dayjs": "1.11.10", + "esbuild": "^0.27.7", "eslint": "8.57.1", "glob": "^7.2.0", "jsdoc": "^4.0.2", @@ -34,6 +37,13 @@ "npm": ">=9" } }, + "e2e": { + "name": "concerto-e2e", + "version": "1.0.0", + "devDependencies": { + "@playwright/test": "^1.60.0" + } + }, "node_modules/@accordproject/concertino": { "resolved": "packages/concertino", "link": true @@ -1944,6 +1954,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "@emnapi/wasi-threads": "1.2.1", "tslib": "^2.4.0" @@ -1956,6 +1967,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "tslib": "^2.4.0" } @@ -1967,6 +1979,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "tslib": "^2.4.0" } @@ -3373,6 +3386,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "@tybys/wasm-util": "^0.10.1" }, @@ -3437,6 +3451,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=14" } @@ -3454,6 +3469,22 @@ "url": "https://opencollective.com/pkgr" } }, + "node_modules/@playwright/test": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.60.0.tgz", + "integrity": "sha512-O71yZIbAh/PxDMNGns37GHBIfrVkEVyn+AXyIa5dOTfb4/xNvRWV+Vv/NMbNCtODB/pO7vLlF2OTmMVLhmr7Ag==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.60.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@rollup/plugin-commonjs": { "version": "22.0.2", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-22.0.2.tgz", @@ -3590,9 +3621,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3607,9 +3635,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3624,9 +3649,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3641,9 +3663,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3658,9 +3677,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3675,9 +3691,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3692,9 +3705,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3709,9 +3719,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3726,9 +3733,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3743,9 +3747,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3760,9 +3761,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3777,9 +3775,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3794,9 +3789,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4563,6 +4555,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "tslib": "^2.4.0" } @@ -5228,7 +5221,8 @@ "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-android-arm64": { "version": "1.12.2", @@ -5242,7 +5236,8 @@ "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-darwin-arm64": { "version": "1.12.2", @@ -5256,7 +5251,8 @@ "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-darwin-x64": { "version": "1.12.2", @@ -5270,7 +5266,8 @@ "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-freebsd-x64": { "version": "1.12.2", @@ -5284,7 +5281,8 @@ "optional": true, "os": [ "freebsd" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-arm-gnueabihf": { "version": "1.12.2", @@ -5298,7 +5296,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-arm-musleabihf": { "version": "1.12.2", @@ -5312,7 +5311,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-arm64-gnu": { "version": "1.12.2", @@ -5322,14 +5322,12 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-arm64-musl": { "version": "1.12.2", @@ -5339,14 +5337,12 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-loong64-gnu": { "version": "1.12.2", @@ -5356,14 +5352,12 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-loong64-musl": { "version": "1.12.2", @@ -5373,14 +5367,12 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-ppc64-gnu": { "version": "1.12.2", @@ -5390,14 +5382,12 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-riscv64-gnu": { "version": "1.12.2", @@ -5407,14 +5397,12 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-riscv64-musl": { "version": "1.12.2", @@ -5424,14 +5412,12 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-s390x-gnu": { "version": "1.12.2", @@ -5441,14 +5427,12 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-x64-gnu": { "version": "1.12.2", @@ -5458,14 +5442,12 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-linux-x64-musl": { "version": "1.12.2", @@ -5475,14 +5457,12 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-openharmony-arm64": { "version": "1.12.2", @@ -5496,7 +5476,8 @@ "optional": true, "os": [ "openharmony" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-wasm32-wasi": { "version": "1.12.2", @@ -5508,6 +5489,7 @@ "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "@emnapi/core": "1.10.0", "@emnapi/runtime": "1.10.0", @@ -5529,7 +5511,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-win32-ia32-msvc": { "version": "1.12.2", @@ -5543,7 +5526,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@unrs/resolver-binding-win32-x64-msvc": { "version": "1.12.2", @@ -5557,7 +5541,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@vitest/coverage-v8": { "version": "3.2.4", @@ -7788,6 +7773,10 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "license": "MIT" }, + "node_modules/concerto-e2e": { + "resolved": "e2e", + "link": true + }, "node_modules/console-browserify": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.2.0.tgz", @@ -12947,6 +12936,7 @@ "os": [ "darwin" ], + "peer": true, "engines": { "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } @@ -16947,6 +16937,53 @@ "node": ">=8" } }, + "node_modules/playwright": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.60.0.tgz", + "integrity": "sha512-hheHdokM8cdqCb0lcE3s+zT4t4W+vvjpGxsZlDnikarzx8tSzMebh3UiFtgqwFwnTnjYQcsyMF8ei2mCO/tpeA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.60.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.60.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz", + "integrity": "sha512-9bW6zvX/m0lEbgTKJ6YppOKx8H3VOPBMOCFh2irXFOT4BbHgrx5hPjwJYLT40Lu+4qtD36qKc/Hn56StUW57IA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/pluralize": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", diff --git a/package.json b/package.json index 48a8e99210..419895a792 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "devDependencies": { + "@playwright/test": "^1.60.0", "@types/path-browserify": "^1.0.3", "colors": "1.4.0", "coveralls-next": "^5.0.0", "dayjs": "1.11.10", + "esbuild": "^0.27.7", "eslint": "8.57.1", "glob": "^7.2.0", "jsdoc": "^4.0.2", @@ -23,7 +25,8 @@ "packages/concerto-util", "packages/concerto-vocabulary", "packages/concerto-linter", - "packages/concerto-linter/default-ruleset" + "packages/concerto-linter/default-ruleset", + "e2e" ], "overrides": { "ajv@^8.0.0": "8.17.1" @@ -42,7 +45,8 @@ "build:level0": "npm run build -w packages/concerto-util", "build:level1": "npm run build -w packages/concerto-cto && npm run build -w packages/concerto-core", "build:level2": "npm run build -w packages/concerto-analysis -w packages/concerto-vocabulary -w packages/concertino -w packages/concerto-linter", - "build:parallel": "npm run build --workspaces --if-present" + "build:parallel": "npm run build --workspaces --if-present", + "test:e2e": "npm run test:e2e -w concerto-e2e" }, "repository": { "type": "git", @@ -58,6 +62,7 @@ ".gitattributes", ".tern-project", "node_modules", + "e2e", "packages", "softhsm", "build.cfg", diff --git a/packages/concertino/package.json b/packages/concertino/package.json index ef5cbc2e16..239f13c915 100644 --- a/packages/concertino/package.json +++ b/packages/concertino/package.json @@ -12,13 +12,14 @@ "scripts": { "clean": "rimraf dist", "prebuild": "npm-run-all clean generate-types", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && npm run build:esm", "postbuild": "cpx \"src/spec/*.json\" dist/spec/", "pretest": "npm-run-all lint", "lint": "eslint .", "test": "vitest run", "test:watch": "vitest", - "generate-types": "cross-env ENABLE_MAP_TYPE=true node scripts/generateTypes.js" + "generate-types": "cross-env ENABLE_MAP_TYPE=true node scripts/generateTypes.js", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -52,5 +53,16 @@ "npm-run-all": "4.1.5", "typescript": "^5.7.2", "vitest": "^3.2.4" - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/packages/concerto-analysis/package.json b/packages/concerto-analysis/package.json index 0c47301fb0..ec4f20ae77 100644 --- a/packages/concerto-analysis/package.json +++ b/packages/concerto-analysis/package.json @@ -12,12 +12,13 @@ "scripts": { "clean": "rimraf dist", "prebuild": "npm-run-all clean", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && npm run build:esm", "pretest": "npm-run-all licchk lint", "lint": "eslint .", "licchk": "license-check-and-add", "test": "jest", - "test:watch": "jest --watchAll" + "test:watch": "jest --watchAll", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -94,5 +95,16 @@ "file": "./HEADER.md" } } - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index 57bc3d8740..46fc94208c 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -23,9 +23,10 @@ "doc": "jsdoc --pedantic --recurse -c jsdoc.json", "test": "cross-env TS_NODE_PROJECT=tsconfig.build.json TZ=UTC nyc mocha -r ts-node/register --recursive -t 10000", "test:watch": "cross-env TZ=UTC nyc mocha -r ts-node/register --watch --recursive -t 10000", - "build": "tsc -p tsconfig.build.json && cpx \"src/*.json\" dist/ && cpx \"src/messages/*.json\" dist/messages/", + "build": "tsc -p tsconfig.build.json && cpx \"src/*.json\" dist/ && cpx \"src/messages/*.json\" dist/messages/ && npm run build:esm", "postbuild": "npm run webpack", - "webpack": "webpack --config webpack.config.js --mode production" + "webpack": "webpack --config webpack.config.js --mode production", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -158,5 +159,19 @@ "branches": 94.8, "functions": 99, "lines": 99 - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": [ + "./dist/dayjs-setup.js", + "./dist/esm/index.mjs" + ] } diff --git a/packages/concerto-core/src/datetimeutil.ts b/packages/concerto-core/src/datetimeutil.ts index 0df07030de..08e09eb68c 100644 --- a/packages/concerto-core/src/datetimeutil.ts +++ b/packages/concerto-core/src/datetimeutil.ts @@ -14,15 +14,7 @@ 'use strict'; -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); -const quarterOfYear = require('dayjs/plugin/quarterOfYear'); -dayjs.extend(quarterOfYear); -const minMax = require('dayjs/plugin/minMax'); -dayjs.extend(minMax); -const duration = require('dayjs/plugin/duration'); -dayjs.extend(duration); +const dayjs = require('./dayjs-setup'); /** * Ensures there is a proper current time diff --git a/packages/concerto-core/src/dayjs-setup.ts b/packages/concerto-core/src/dayjs-setup.ts new file mode 100644 index 0000000000..7aedfbf39f --- /dev/null +++ b/packages/concerto-core/src/dayjs-setup.ts @@ -0,0 +1,28 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const dayjs = require('dayjs'); +const utc = require('dayjs/plugin/utc'); +const quarterOfYear = require('dayjs/plugin/quarterOfYear'); +const minMax = require('dayjs/plugin/minMax'); +const duration = require('dayjs/plugin/duration'); + +dayjs.extend(utc); +dayjs.extend(quarterOfYear); +dayjs.extend(minMax); +dayjs.extend(duration); + +export = dayjs; diff --git a/packages/concerto-core/src/factory.ts b/packages/concerto-core/src/factory.ts index a13f6efd7d..6f52f4d9cc 100644 --- a/packages/concerto-core/src/factory.ts +++ b/packages/concerto-core/src/factory.ts @@ -31,9 +31,7 @@ const ValidatedResource = require('./model/validatedresource'); const uuid = require('uuid'); -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); +const dayjs = require('./dayjs-setup'); // Types needed for TypeScript generation. /* eslint-disable no-unused-vars */ diff --git a/packages/concerto-core/src/model/typed.ts b/packages/concerto-core/src/model/typed.ts index 7007f3712b..9e3836ddab 100644 --- a/packages/concerto-core/src/model/typed.ts +++ b/packages/concerto-core/src/model/typed.ts @@ -14,12 +14,9 @@ 'use strict'; -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); +const dayjs = require('../dayjs-setup'); const Util = require('@accordproject/concerto-util').NullUtil; -dayjs.extend(utc); - // Types needed for TypeScript generation. /* eslint-disable no-unused-vars */ /* istanbul ignore next */ diff --git a/packages/concerto-core/src/serializer/jsonpopulator.ts b/packages/concerto-core/src/serializer/jsonpopulator.ts index e48380af1c..e87ae2db47 100644 --- a/packages/concerto-core/src/serializer/jsonpopulator.ts +++ b/packages/concerto-core/src/serializer/jsonpopulator.ts @@ -20,15 +20,7 @@ const Relationship = require('../model/relationship'); const Util = require('@accordproject/concerto-util').NullUtil; const ModelUtil = require('../modelutil'); const ValidationException = require('./validationexception'); -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); -const quarterOfYear = require('dayjs/plugin/quarterOfYear'); -dayjs.extend(quarterOfYear); -const minMax = require('dayjs/plugin/minMax'); -dayjs.extend(minMax); -const duration = require('dayjs/plugin/duration'); -dayjs.extend(duration); +const dayjs = require('../dayjs-setup'); import type Factory = require('../factory'); import type ModelManager = require('../modelmanager'); import type Declaration = require('../introspect/declaration'); diff --git a/packages/concerto-core/src/serializer/resourcevalidator.ts b/packages/concerto-core/src/serializer/resourcevalidator.ts index 8395bddc4e..4e91e421a7 100644 --- a/packages/concerto-core/src/serializer/resourcevalidator.ts +++ b/packages/concerto-core/src/serializer/resourcevalidator.ts @@ -22,9 +22,7 @@ const ModelUtil = require('../modelutil'); const ValidationException = require('./validationexception'); const Globalize = require('../globalize'); -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); +const dayjs = require('../dayjs-setup'); /** *

diff --git a/packages/concerto-core/src/serializer/valuegenerator.ts b/packages/concerto-core/src/serializer/valuegenerator.ts index 0efd966aa2..f309b51da2 100644 --- a/packages/concerto-core/src/serializer/valuegenerator.ts +++ b/packages/concerto-core/src/serializer/valuegenerator.ts @@ -16,9 +16,7 @@ const { loremIpsum } = require('lorem-ipsum'); const RandExp = require('randexp'); -const dayjs = require('dayjs'); -const utc = require('dayjs/plugin/utc'); -dayjs.extend(utc); +const dayjs = require('../dayjs-setup'); /** * Generate a random number within a given range with diff --git a/packages/concerto-cto/package.json b/packages/concerto-cto/package.json index 868377de0e..a576c90628 100644 --- a/packages/concerto-cto/package.json +++ b/packages/concerto-cto/package.json @@ -23,9 +23,10 @@ "doc": "jsdoc --pedantic --recurse -c jsdoc.json", "test": "nyc mocha -r ts-node/register --recursive -t 10000", "test:watch": "nyc mocha -r ts-node/register --watch --recursive -t 10000", - "build": "npm run parser && tsc -p tsconfig.build.json", + "build": "npm run parser && tsc -p tsconfig.build.json && npm run build:esm", "postbuild": "npm run webpack", - "webpack": "webpack --config webpack.config.js --mode production" + "webpack": "webpack --config webpack.config.js --mode production", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -138,5 +139,16 @@ "branches": 100, "functions": 100, "lines": 100 - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/packages/concerto-linter/package.json b/packages/concerto-linter/package.json index c3b2e79015..5159a7a54a 100644 --- a/packages/concerto-linter/package.json +++ b/packages/concerto-linter/package.json @@ -12,12 +12,13 @@ "scripts": { "clean": "rimraf dist", "prebuild": "npm-run-all clean && cd ./default-ruleset && npm run build", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && npm run build:esm", "pretest": "npm-run-all lint", "lint": "eslint .", "lint:fix": "eslint . --fix", "test": "jest", - "test:watch": "jest --watchAll" + "test:watch": "jest --watchAll", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -51,5 +52,16 @@ "rimraf": "^6.0.1", "ts-jest": "^29.2.5", "typescript": "5.7.2" - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/packages/concerto-util/package.json b/packages/concerto-util/package.json index 4b46ceae8e..1c8be492a2 100644 --- a/packages/concerto-util/package.json +++ b/packages/concerto-util/package.json @@ -22,9 +22,10 @@ "doc": "jsdoc --pedantic --recurse -c jsdoc.json", "test": "nyc mocha -r ts-node/register --recursive -t 10000", "test:watch": "nyc mocha -r ts-node/register --watch --recursive -t 10000", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && npm run build:esm", "postbuild": "npm run webpack", - "webpack": "webpack --config webpack.config.js --mode production" + "webpack": "webpack --config webpack.config.js --mode production", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -129,5 +130,16 @@ "branches": 94, "functions": 100, "lines": 100 - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/packages/concerto-vocabulary/package.json b/packages/concerto-vocabulary/package.json index dabfa6e3f2..83df7e90b6 100644 --- a/packages/concerto-vocabulary/package.json +++ b/packages/concerto-vocabulary/package.json @@ -21,7 +21,8 @@ "test": "nyc mocha -r ts-node/register --recursive -t 10000", "test:updateSnapshots": "UPDATE_SNAPSHOT=1 nyc mocha -r ts-node/register --recursive -t 10000", "test:watch": "nyc mocha -r ts-node/register --watch --recursive -t 10000", - "build": "tsc -p tsconfig.build.json" + "build": "tsc -p tsconfig.build.json && npm run build:esm", + "build:esm": "node ../../scripts/build-esm.js" }, "repository": { "type": "git", @@ -126,5 +127,16 @@ "branches": 88, "functions": 98, "lines": 95 - } + }, + "module": "dist/esm/index.mjs", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/esm/index.mjs", + "require": "./dist/index.js" + }, + "./package.json": "./package.json", + "./dist/*": "./dist/*" + }, + "sideEffects": false } diff --git a/scripts/build-esm.js b/scripts/build-esm.js new file mode 100644 index 0000000000..10fca20b76 --- /dev/null +++ b/scripts/build-esm.js @@ -0,0 +1,62 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const { builtinModules } = require('module'); +const esbuild = require('esbuild'); + +const packageDir = process.cwd(); +const packageJsonPath = path.join(packageDir, 'package.json'); +const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); +const entryPoint = path.join(packageDir, 'src', 'index.ts'); +const outfile = path.join(packageDir, 'dist', 'esm', 'index.mjs'); +const isNodeOnlyPackage = packageJson.name === '@accordproject/concerto-linter'; + +const workspacePackages = [ + '@accordproject/concerto-analysis', + '@accordproject/concerto-core', + '@accordproject/concerto-cto', + '@accordproject/concerto-linter', + '@accordproject/concerto-util', + '@accordproject/concerto-vocabulary', + '@accordproject/concertino', +].filter(name => name !== packageJson.name); + +const packageExternal = isNodeOnlyPackage ? [...workspacePackages, 'fsevents', 'fsevents/*', '*.node'] : workspacePackages; +const expandExternal = name => name.includes('*') ? [name] : [name, `${name}/*`]; + +const external = [ + ...packageExternal.flatMap(expandExternal), + ...builtinModules, + ...builtinModules.map(name => `node:${name}`), +]; + +esbuild.buildSync({ + entryPoints: [entryPoint], + outfile, + bundle: true, + format: 'esm', + platform: isNodeOnlyPackage ? 'node' : 'browser', + mainFields: isNodeOnlyPackage ? ['module', 'main'] : ['browser', 'module', 'main'], + target: 'es2020', + sourcemap: true, + external, + banner: { + js: 'import { createRequire as __createRequire } from "module";\nconst require = __createRequire(import.meta.url);', + }, + logLevel: 'info', +}); From ea7f35c447324058fc3efd61c4b991fa84755ebd Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Sun, 14 Jun 2026 20:51:43 +0100 Subject: [PATCH 2/8] fix(concerto-core): remove ESM entrypoint from sideEffects to enable package-level tree shaking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Listing `./dist/esm/index.mjs` in sideEffects prevented bundlers from skipping concerto-core entirely when nothing from it is imported. Instead, emit `dist/esm/dayjs-setup.js` as a separate file and reference that in sideEffects — keeping the real side effect (dayjs.extend() calls) declared while allowing the main ESM bundle to be tree-shaken at the package boundary. Verified: importing only concerto-util produces a 59 KB bundle; adding concerto-core jumps to 1.46 MB, confirming the package is correctly excluded when unused. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: Matt Roberts --- packages/concerto-core/package.json | 2 +- scripts/build-esm.js | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index 46fc94208c..86e52bd4a3 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -172,6 +172,6 @@ }, "sideEffects": [ "./dist/dayjs-setup.js", - "./dist/esm/index.mjs" + "./dist/esm/dayjs-setup.js" ] } diff --git a/scripts/build-esm.js b/scripts/build-esm.js index 10fca20b76..70c7c42259 100644 --- a/scripts/build-esm.js +++ b/scripts/build-esm.js @@ -25,6 +25,7 @@ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); const entryPoint = path.join(packageDir, 'src', 'index.ts'); const outfile = path.join(packageDir, 'dist', 'esm', 'index.mjs'); const isNodeOnlyPackage = packageJson.name === '@accordproject/concerto-linter'; +const hasDayjsSetup = fs.existsSync(path.join(packageDir, 'src', 'dayjs-setup.ts')); const workspacePackages = [ '@accordproject/concerto-analysis', @@ -45,9 +46,7 @@ const external = [ ...builtinModules.map(name => `node:${name}`), ]; -esbuild.buildSync({ - entryPoints: [entryPoint], - outfile, +const commonBuildOptions = { bundle: true, format: 'esm', platform: isNodeOnlyPackage ? 'node' : 'browser', @@ -59,4 +58,21 @@ esbuild.buildSync({ js: 'import { createRequire as __createRequire } from "module";\nconst require = __createRequire(import.meta.url);', }, logLevel: 'info', +}; + +esbuild.buildSync({ + ...commonBuildOptions, + entryPoints: [entryPoint], + outfile, }); + +// For packages with dayjs-setup, also emit it as a separate ESM file so the +// sideEffects field in package.json can reference it without marking the entire +// index.mjs as side-effectful. +if (hasDayjsSetup) { + esbuild.buildSync({ + ...commonBuildOptions, + entryPoints: [path.join(packageDir, 'src', 'dayjs-setup.ts')], + outfile: path.join(packageDir, 'dist', 'esm', 'dayjs-setup.js'), + }); +} From 3073809b87571803dd01a02f2da22aa96ea55ecf Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Fri, 28 Aug 2026 10:04:27 +0100 Subject: [PATCH 3/8] fix(concerto-core): emit dayjs-setup as .mjs and document build order The ESM dayjs-setup output lived at dist/esm/dayjs-setup.js. Since the package is not "type": "module", Node parses a .js file as CommonJS, so an ESM file with that extension is ambiguous. Emit it as .mjs and point the sideEffects entry at the .mjs path so the dayjs.extend() side effect stays correctly declared. Also document in DEVELOPERS.md that the monorepo must be built in dependency order (npm run build), because each package's exports.import now resolves to dist/esm/index.mjs. Addresses review feedback on PR #1263. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- DEVELOPERS.md | 2 ++ packages/concerto-core/package.json | 2 +- scripts/build-esm.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DEVELOPERS.md b/DEVELOPERS.md index 9b8e7cce2e..b0c7523ec0 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -42,6 +42,8 @@ npm run test > **Note:** The build step is required because some packages (like `concerto-linter`) depend on other workspace packages that need to be compiled first. The CI workflows follow this same pattern: build first, then test. +> **Note:** Always build the whole monorepo with `npm run build` (which builds in dependency order), not a single package in isolation. Because each package's `exports.import` condition resolves to its `dist/esm/index.mjs`, building one package alone can fail if a workspace dependency's ESM output does not yet exist. `npm run build:ordered` (the default `build` script) handles this ordering; CI relies on it too. + If you're working on a specific package, you can run tests for just that package: ```shell diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index 86e52bd4a3..0d6cc7e39b 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -172,6 +172,6 @@ }, "sideEffects": [ "./dist/dayjs-setup.js", - "./dist/esm/dayjs-setup.js" + "./dist/esm/dayjs-setup.mjs" ] } diff --git a/scripts/build-esm.js b/scripts/build-esm.js index 70c7c42259..437b9d7d66 100644 --- a/scripts/build-esm.js +++ b/scripts/build-esm.js @@ -73,6 +73,6 @@ if (hasDayjsSetup) { esbuild.buildSync({ ...commonBuildOptions, entryPoints: [path.join(packageDir, 'src', 'dayjs-setup.ts')], - outfile: path.join(packageDir, 'dist', 'esm', 'dayjs-setup.js'), + outfile: path.join(packageDir, 'dist', 'esm', 'dayjs-setup.mjs'), }); } From 63b4dd178372444acb69bb5376387b91cfcd6599 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Fri, 28 Aug 2026 10:42:26 +0100 Subject: [PATCH 4/8] fix(concerto): address Copilot review on ESM tree-shaking PR - e2e: import Page as a type-only import (it is used only as a type), avoiding a runtime named-import mismatch under some TS transpile modes. - build-esm: gate the createRequire shim banner to the Node-only build. Browser-targeted .mjs outputs no longer carry a Node-only `import ... from "module"`, which could break downstream browser bundlers. Verified the browser bundles emit zero runtime require() calls (externals resolve as ESM imports), so the shim was unused there; the node-only package still receives it. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- e2e/tests/browser-bundles.spec.ts | 2 +- scripts/build-esm.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/e2e/tests/browser-bundles.spec.ts b/e2e/tests/browser-bundles.spec.ts index 82eb64fce9..da2678ef2d 100644 --- a/e2e/tests/browser-bundles.spec.ts +++ b/e2e/tests/browser-bundles.spec.ts @@ -12,7 +12,7 @@ * limitations under the License. */ -import { test, expect, Page } from '@playwright/test'; +import { test, expect, type Page } from '@playwright/test'; import * as path from 'path'; const CTO_BUNDLE = path.resolve(__dirname, '../../packages/concerto-cto/dist/concerto-cto.js'); diff --git a/scripts/build-esm.js b/scripts/build-esm.js index 437b9d7d66..113b7898aa 100644 --- a/scripts/build-esm.js +++ b/scripts/build-esm.js @@ -54,10 +54,16 @@ const commonBuildOptions = { target: 'es2020', sourcemap: true, external, - banner: { - js: 'import { createRequire as __createRequire } from "module";\nconst require = __createRequire(import.meta.url);', - }, logLevel: 'info', + // Only the Node-only build needs the createRequire shim: its externalised + // Node builtins are emitted as runtime require() calls. Browser-targeted + // builds must not carry a Node-only `import ... from "module"`, which would + // break downstream browser bundlers, so the banner is gated accordingly. + ...(isNodeOnlyPackage ? { + banner: { + js: 'import { createRequire as __createRequire } from "module";\nconst require = __createRequire(import.meta.url);', + }, + } : {}), }; esbuild.buildSync({ From 62505415ed79467afd0c876a84d7967f826a129a Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Fri, 28 Aug 2026 11:03:38 +0100 Subject: [PATCH 5/8] fix(concerto): stub Node builtins in browser ESM instead of bare imports The browser-targeted ESM build externalised Node builtins, leaving bare `import "fs"` (concerto-core, concerto-util) and `import "path"` (concerto-util) in dist/esm/index.mjs. These only resolve in downstream consumers that ship Node-polyfill/fallback infrastructure; a stricter browser bundler would fail to resolve them. Stub Node builtins to empty modules for browser builds via an esbuild plugin (requires the async build API), matching the parity the webpack UMD build already achieves via resolve.fallback (fs/path -> false). The node-only linter build still externalises builtins and keeps its createRequire banner. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- issues.jsonl | 12 +++++++ scripts/build-esm.js | 78 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 issues.jsonl diff --git a/issues.jsonl b/issues.jsonl new file mode 100644 index 0000000000..8829cecc8e --- /dev/null +++ b/issues.jsonl @@ -0,0 +1,12 @@ +{"id":"concerto-126","title":"Stage 0: Rebase fix/tree-shaking-sideeffects onto main + capture baseline","description":"Capture clean-main build+test baseline (oracle for 'tests pass unchanged'). Rebase branch (10 commits behind), resolve conflicts in root package.json/package-lock.json and per-package version fields. npm ci + ordered build on rebased branch. Post baseline test counts as notes.","notes":"Stage 0 COMPLETE (2026-08-28).\nBranch ts-rebase = origin/main + 3 commits: 374393dbf (Rishabh feat), ea7f35c44 (sideEffects fix), 3073809b8 (dayjs .mjs + DEVELOPERS.md build-order note). Rebase clean, no conflicts. Stray issues.jsonl beads artifact stripped from deliverable commit.\nSmoke build: npm ci + ordered 'npm run build' =\u003e STAGE0_EXIT=0. All 7 packages emit dist/esm/index.mjs. concerto-core emits dist/esm/dayjs-setup.mjs (26801 bytes, 5 extend refs =\u003e UTC/quarterOfYear/duration/minMax side effect intact). G1 preliminary PASS.\nBaseline oracle for G2: green main build+test captured earlier (exit 0, 0 failures) — verifier A diffs against it.\nWorktree: /tmp/concerto-ts-rebase","status":"closed","priority":1,"issue_type":"task","assignee":"mttrbrts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:49Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:07:40Z","started_at":"2026-08-28T09:00:19Z","closed_at":"2026-08-28T09:07:40Z","close_reason":"Stage 0 done: clean rebase, clean commit, smoke build green, all ESM artifacts present","dependency_count":0,"dependent_count":8,"comment_count":0} +{"id":"concerto-e2m","title":"Harden browser ESM build: stub Node builtins instead of emitting bare import \"fs\"/\"path\"","description":"PR #1263's browser-targeted ESM (dist/esm/index.mjs) still emits bare Node-builtin imports (import \"fs\" in concerto-core and concerto-util, import \"path\" in concerto-util) because scripts/build-esm.js externalizes builtinModules for all builds. This only resolves in downstream consumers that ship Node-polyfill/fallback infrastructure (concerto-playground via vite-plugin-node-polyfills, template-engine via webpack resolve.fallback). A stricter consumer (plain esbuild/rollup/Vite without polyfills) would fail with unresolved 'fs'/'path'. The existing webpack UMD build already avoids this by mapping fs/tls/net/child_process/os/path -\u003e false (empty stub). Fix: for browser builds only, stub Node builtins to empty modules via an esbuild plugin instead of externalizing them, achieving parity with the UMD. Keep externalizing builtins for the node-only linter build.","status":"in_progress","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T09:56:23Z","created_by":"Matt Roberts","updated_at":"2026-08-28T09:56:32Z","started_at":"2026-08-28T09:56:32Z","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"concerto-yx7","title":"Address Copilot review feedback on PR #1263","description":"Two inline Copilot comments: (1) e2e/tests/browser-bundles.spec.ts imports Page as runtime value but uses it only as a type -\u003e type-only import. (2) scripts/build-esm.js injects createRequire banner unconditionally, leaking a Node-only 'module' import into browser-targeted .mjs outputs -\u003e gate banner to the node-only build. Verify browser ESM builds still succeed and emit no 'module' import.","notes":"Fixed in commit 63b4dd178, pushed to PR #1263 (fast-forward). (1) type-only Page import; (2) createRequire banner gated to node-only build. Verified: browser .mjs have 0 'module' imports + 0 require() calls; node .mjs keeps shim; Playwright 3/3. Replied to both Copilot threads.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T09:39:14Z","created_by":"Matt Roberts","updated_at":"2026-08-28T09:43:39Z","started_at":"2026-08-28T09:39:20Z","closed_at":"2026-08-28T09:43:39Z","close_reason":"Both Copilot review comments addressed, verified, pushed to PR #1263","dependency_count":0,"dependent_count":0,"comment_count":0} +{"id":"concerto-08k","title":"Spike E: per-export native-ESM migration measurement (leaf module) — GO/NO-GO","description":"Throwaway worktree. Migrate one low-fan-in concerto-core leaf module export=/import=require -\u003e native ESM. Measure single-export vs whole-index bundle bytes. Write GO/NO-GO memo. DISCARD worktree; nothing merges. Model: sonnet.","notes":"## Spike E — GO/NO-GO Memo: Native ESM Migration for Per-Export Tree-Shaking\n\n### Setup\n- Worktree: /tmp/wt-spike at commit 3073809b8 (rebased branch)\n- Leaf module tested: packages/concerto-core/src/securityexception.ts\n- Reason chosen: zero internal ./ requires, only one external dep (BaseException from @accordproject/concerto-util)\n- Measurement tool: esbuild --bundle --minify --platform=node\n\n---\n\n### BEFORE Baseline (current: esbuild bundle:true, CJS-in-ESM blob)\n\n| Import | Bundle size |\n|--------|------------|\n| 1 export (SecurityException only) | 595,862 bytes (596 KB) |\n| All exports (export * from index) | 596,715 bytes (597 KB) |\n| Delta (1 export vs all) | 853 bytes (0.14%) |\n\n**Interpretation:** Virtually no per-export tree-shaking. Importing one class vs the entire library differs by less than 1 KB because the whole concerto-core source (all 58 TS files + third-party deps) is pre-bundled into a single CJS-in-ESM blob using __commonJS/__esm wrappers. Bundlers cannot tree-shake inside this blob.\n\n---\n\n### AFTER Measurement (migrated securityexception.ts to native ESM, bundle:false)\n\nMigration performed: Changed securityexception.ts from:\n const { BaseException } = require('@accordproject/concerto-util'); ... export = SecurityException;\nTo:\n import { BaseException } from '@accordproject/concerto-util'; ... export { SecurityException };\n\nCompiled with esbuild bundle:false → 385-byte unbundled .mjs file with live import statement.\n\nConsumer bundler then tree-shakes the import chain (SecurityException → BaseException only).\n\n| Import | Bundle size |\n|--------|------------|\n| 1 export (SecurityException from unbundled .mjs) | 22,908 bytes (22 KB) |\n| Reduction vs BEFORE | **96.2%** (573 KB saved) |\n\nThe 22 KB is: SecurityException itself + the portion of @accordproject/concerto-util's bundled blob needed for BaseException. Note: concerto-util is ALSO a bundled CJS-in-ESM blob — if concerto-util were also migrated to native ESM, the after-bundle would be even smaller (BaseException is ~30 lines; full tree-shaken size would be \u003c1 KB).\n\n---\n\n### Migration Cost Assessment\n\n**Files requiring migration:** 58 total with export = / CJS require patterns.\n\n**Pure leaf files (no internal ./ requires at all):** 4 files:\n - securityexception.ts — trivial, migrated in spike (0 internal deps)\n - metamodelexception.ts — only external concerto-util\n - dayjs-setup.ts — external only \n - serializer/validationexception.ts — external only\n\n**Files with only const X = require('./internal') patterns:** ~38 more files\n - These use CJS require syntax, not TypeScript import = require\n - Each migrated file forces any file that requires IT to also migrate\n - The migration is a bottom-up topological traversal of the import graph\n\n**Migration pattern per file:**\n 1. Replace: const X = require('./foo') → import X from './foo.js'\n 2. Replace: const { X, Y } = require('@external') → import { X, Y } from '@external'\n 3. Replace: export = ClassName → export { ClassName }; export default ClassName;\n 4. If file uses globalize.ts (Globalize) — must migrate globalize.ts first\n\n**Blocker observed:** Most files depend on concerto-util which is ALSO a bundled CJS-in-ESM blob. This means even after migrating all 58 concerto-core files, tree-shaking INTO concerto-util would still be blocked. Full win requires migrating concerto-util too (estimated ~40 files in packages/concerto-util/src).\n\n**Estimated effort for concerto-core alone:** 58 files, topological order. Most files are mechanical find-replace. Complex files: basemodelmanager.ts (20 internal requires), serializer/jsonpopulator.ts (8+4 requires), factory.ts (10 internal requires). Estimate: 2-3 developer-days for an engineer familiar with the codebase, including test verification.\n\n**tsc TS1203 status:** Not hit during spike because esbuild was used (not tsc) for the after measurement. A tsc-based unbundled ESM build would require tsconfig with module: ESNext or ES2020, which IS supported by tsc — the TS1203 error only fires when you use export = WITH a module: es* setting. Removing export = (replacing with export {}) fully resolves TS1203.\n\n---\n\n### Build Path for Unbundled ESM\n\nReplace the current build:esm step (esbuild bundle:true → single index.mjs blob) with:\n - tsc --module ES2020 --moduleResolution bundler --outDir dist/esm (unbundled, one .mjs per .ts file)\n - OR esbuild with bundle:false and splitting:true\n - package.json exports map to individual files OR a thin re-export barrel\n\nThe build:esm script (scripts/build-esm.js) would be simplified — no bundling needed for the ESM path.\n\n---\n\n### VERDICT: GO (conditional on concerto-util co-migration)\n\n**GO** — the per-export tree-shaking benefit is massive and real: 96.2% bundle reduction for a leaf import. The migration pattern is mechanical and well-understood.\n\n**Condition:** Full wins require concerto-util to also migrate from its CJS-in-ESM bundle to native ESM. Without that, consumers still pull in all of concerto-util (~60 KB minified) even for leaf imports. With it, a SecurityException import would likely be \u003c2 KB total.\n\n**Recommended epic scope:**\n 1. Migrate concerto-util to native ESM (est. 1-2 days)\n 2. Migrate concerto-core to native ESM top-down (est. 2-3 days)\n 3. Update tsconfig.build.json: module → ES2020, moduleResolution → bundler\n 4. Replace build:esm esbuild bundle:true with tsc unbundled pass\n 5. Add exports map entries per module for deep imports (optional)\n 6. Verify all downstream packages (concerto-analysis, concerto-vocabulary, etc.) still build","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:53Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:18:01Z","started_at":"2026-08-28T09:11:31Z","closed_at":"2026-08-28T09:18:01Z","close_reason":"Spike complete: GO — 96.2% bundle reduction (596KB→23KB) for leaf import; 58-file migration is mechanical, conditional on concerto-util co-migration","dependencies":[{"issue_id":"concerto-08k","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:18Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":2,"comment_count":0} +{"id":"concerto-vnp","title":"Review nit: rename dayjs-setup ESM output to .mjs + update sideEffects/build-esm.js","description":"Package is not type:module, so dist/esm/dayjs-setup.js is parsed as CJS. Rename to .mjs, update sideEffects entry and scripts/build-esm.js outfile. Guarded by G6. Per Rishabh review comment on PR #1263.","status":"closed","priority":2,"issue_type":"task","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:52Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:06:39Z","closed_at":"2026-08-28T09:06:39Z","close_reason":"Done in commit 3073809b8: build-esm.js emits dist/esm/dayjs-setup.mjs; sideEffects updated to ./dist/esm/dayjs-setup.mjs","dependencies":[{"issue_id":"concerto-vnp","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:15Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":2,"comment_count":0} +{"id":"concerto-820","title":"Agent D: Playwright browser-bundle E2E (G4)","description":"Run e2e/tests/browser-bundles.spec.ts. Report pass/fail + trace on failure as notes. Model: haiku.","notes":"e2e location: /tmp/concerto-ts-rebase/e2e. Playwright: 3 passed / 0 failed. Browser bundles (CTO parser, core ModelManager, dayjs plugins) all load and function correctly in UMD format. VERDICT: PASS","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:51Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:13:32Z","started_at":"2026-08-28T09:11:05Z","closed_at":"2026-08-28T09:13:32Z","close_reason":"Closed","dependencies":[{"issue_id":"concerto-820","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:14Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} +{"id":"concerto-8qc","title":"Agent C: Non-breaking compat via packed tarballs (G5,G6)","description":"npm pack all 7 packages; install into scratch consumers: CJS require, ESM import, deep dist/* import, TS .d.ts resolution under node16/nodenext, UMD in browser context. dayjs plugins work in CJS+ESM. Record per-consumer results as notes. Model: sonnet.","notes":"G5(a) CJS: PASS. G5(b) ESM: PASS. G5(c) deep-import (dist/* escape hatch): PASS - require('@accordproject/concerto-core/dist/datetimeutil.js') resolves and returns dayjs obj. G5(d) node16 types: PASS (non-breaking) - identical 5 pre-existing TS8023 JSDoc @extends errors exist on published 4.2.0 AND PR branch; PR introduces zero new type errors. G6 dayjs CJS: PASS - fromJSON/toJSON DateTime round-trip works, UTC plugin active (output 2024-01-15T13:00:00.000+01:00). G6 dayjs ESM: PASS - same round-trip works via ESM index.mjs path. VERDICT: PASS","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:50Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:16:32Z","started_at":"2026-08-28T09:10:54Z","closed_at":"2026-08-28T09:16:32Z","close_reason":"Closed","dependencies":[{"issue_id":"concerto-8qc","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:13Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} +{"id":"concerto-un6","title":"Agent B: Rollup tree-shaking measurement harness (G3)","description":"Author+run Rollup + @rollup/plugin-node-resolve harness against dist/esm/*.mjs. Measure: util-only entry (assert excludes concerto-core, ~\u003c=120KB) vs ModelManager entry (~1.4-1.5MB). Record byte counts as notes. Model: sonnet.","notes":"util-only bundle: 22,503 bytes (22KB), contains concerto-core? NO (0 hits for ModelManager/IllegalModelException). ModelManager bundle: 579,052 bytes (565KB). Both bundles built cleanly with rollup+terser ESM. Thresholds: util well under 120KB cap; core bundle is large as expected. VERDICT: PASS - package-level tree-shaking works; importing only concerto-util does not pull in concerto-core code.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:50Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:12:11Z","started_at":"2026-08-28T09:10:28Z","closed_at":"2026-08-28T09:12:11Z","close_reason":"G3 PASS: util-only bundle=22KB (no concerto-core symbols), ModelManager bundle=565KB. Package-level tree-shaking verified via rollup+terser ESM bundles.","dependencies":[{"issue_id":"concerto-un6","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:13Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} +{"id":"concerto-isg","title":"Agent A: Build + full test verification vs baseline (G1,G2,G6)","description":"In isolated worktree on rebased branch: npm ci, ordered build (all 7 packages emit CJS/ESM/UMD; core emits dist/esm/dayjs-setup.mjs). Run full test suite; compare pass set to baseline. Assert git diff shows ZERO changes to *.spec.ts/test/**. dayjs setCurrentTime works. Post results as notes; close if green, reopen with details if red. Model: haiku.","notes":"**VERIFICATION PASS**\n\nG1 (ESM artifacts): PASS\n - All 7 packages emit dist/esm/index.mjs ✓\n - concerto-core emits dist/esm/dayjs-setup.mjs ✓\n\nG2 (Test suite \u0026 file integrity): PASS\n - Build exit code: 0 ✓\n - Total tests: 1,679 passing, 0 failing (concerto-core: 1,276p; concerto-analysis: 163p; concerto-util: 151p; concerto-vocabulary: 89p; concerto-linter: 18p; linter-ruleset: 19p)\n - Test file diff: 1 ADDED (e2e/tests/browser-bundles.spec.ts) — no modifications/deletions ✓\n\nG6 (dayjs/DateTimeUtil): PASS\n - DateTimeUtil suite fully green (dayjs conversion tests included and passing) ✓\n\n**VERDICT: PASS** — Branch 3073809b8 matches baseline oracle (main). All gates met.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:49Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:13:00Z","started_at":"2026-08-28T09:10:14Z","closed_at":"2026-08-28T09:13:00Z","close_reason":"G1+G2+G6 all PASS: ESM artifacts present, 1679 tests green (0 failing), test files clean (only 1 new file added), dayjs suite passing. Rebased branch 3073809b8 verified against main baseline.","dependencies":[{"issue_id":"concerto-isg","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:12Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-isg","depends_on_id":"concerto-vnp","type":"blocks","created_at":"2026-08-28T09:59:18Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":2,"dependent_count":1,"comment_count":0} +{"id":"concerto-a6y","title":"Epic: Complete tree-shaking support (#1261) — land PR #1263","description":"Refresh and land PR #1263 (fix/tree-shaking-sideeffects) on current main. Package-level tree-shaking + additive ESM + browser-bundle validation, non-breaking, all existing tests pass unchanged. Plus a throwaway spike measuring per-export migration. See plan-issue-1261-tree-shaking.md. GitHub issue: https://github.com/accordproject/concerto/issues/1261","notes":"All acceptance gates verified 2026-08-28 on branch ts-rebase (=fix/tree-shaking-sideeffects rebased on main, HEAD 3073809b8):\nG1 build/artifacts PASS · G2 tests 1679 pass/0 fail, no existing-test edits PASS · G3 pkg tree-shaking (util-only 22.5KB, no core; ModelManager 579KB) PASS · G4 Playwright 3/3 PASS · G5 compat CJS/ESM/deep/node16-types PASS (only 5 pre-existing TS8023 errors, no new) · G6 dayjs both module systems PASS · G7 spike GO-conditional (1 export 595,862-\u003e22,908 B, 96.2%).\nREMAINING: force-push ts-rebase -\u003e PR #1263 branch is BLOCKED pending explicit human approval (destructive public-branch push). Then update PR body + human merge. DO NOT auto-merge.","status":"open","priority":2,"issue_type":"feature","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:14Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:25:35Z","dependencies":[{"issue_id":"concerto-a6y","depends_on_id":"concerto-08k","type":"blocks","created_at":"2026-08-28T09:59:26Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:21Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-820","type":"blocks","created_at":"2026-08-28T09:59:24Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-8qc","type":"blocks","created_at":"2026-08-28T09:59:24Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-isg","type":"blocks","created_at":"2026-08-28T09:59:22Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-j93","type":"blocks","created_at":"2026-08-28T09:59:26Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-un6","type":"blocks","created_at":"2026-08-28T09:59:23Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-vnp","type":"blocks","created_at":"2026-08-28T09:59:25Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":8,"dependent_count":0,"comment_count":0} +{"id":"concerto-334","title":"Follow-up Epic: full concerto-core native-ESM migration (per-export tree-shaking)","description":"Migrate all 58 concerto-core/src files from export=/import=require to native ESM so bundlers can drop unused exports. Blocked on Spike E findings. Larger refactor, separate PR, stresses 'tests pass unchanged'.","notes":"GitHub issue: https://github.com/accordproject/concerto/issues/1304 (created 2026-08-28)","status":"open","priority":3,"issue_type":"feature","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:53Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:35:50Z","dependencies":[{"issue_id":"concerto-334","depends_on_id":"concerto-08k","type":"blocks","created_at":"2026-08-28T09:59:19Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} +{"id":"concerto-j93","title":"Review nit: document local build-order gotcha in DEVELOPERS.md","description":"Building concerto-core alone fails until concerto-cto ESM dist exists (exports.import resolves symlink to dist/esm/index.mjs before build). Add note; confirm build:ordered handles it in CI.","status":"closed","priority":3,"issue_type":"task","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:52Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:06:43Z","closed_at":"2026-08-28T09:06:43Z","close_reason":"Done in commit 3073809b8: DEVELOPERS.md documents mandatory ordered monorepo build","dependencies":[{"issue_id":"concerto-j93","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:17Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} diff --git a/scripts/build-esm.js b/scripts/build-esm.js index 113b7898aa..e07975103e 100644 --- a/scripts/build-esm.js +++ b/scripts/build-esm.js @@ -40,12 +40,45 @@ const workspacePackages = [ const packageExternal = isNodeOnlyPackage ? [...workspacePackages, 'fsevents', 'fsevents/*', '*.node'] : workspacePackages; const expandExternal = name => name.includes('*') ? [name] : [name, `${name}/*`]; -const external = [ - ...packageExternal.flatMap(expandExternal), +const builtinSpecifiers = new Set([ ...builtinModules, ...builtinModules.map(name => `node:${name}`), +]); + +// The Node-only build keeps builtins external (emitted as runtime require() +// calls). Browser builds must not resolve — or carry bare imports of — Node +// builtins, since a downstream browser bundler without Node polyfills would +// fail to resolve `import "fs"`. Instead we stub them to empty modules, matching +// the parity the existing webpack UMD build achieves via resolve.fallback +// (fs/tls/net/child_process/os/path -> false). A dependency that remaps a +// builtin through its own `browser` field is resolved by esbuild before this +// plugin runs, so genuine browser shims (e.g. crypto-browserify) still win. +const external = [ + ...packageExternal.flatMap(expandExternal), + ...(isNodeOnlyPackage + ? [...builtinModules, ...builtinModules.map(name => `node:${name}`)] + : []), ]; +const stubNodeBuiltinsPlugin = { + name: 'stub-node-builtins', + setup(build) { + build.onResolve({ filter: /^(node:|[a-z])/ }, args => { + if (args.path.startsWith('node:') || builtinSpecifiers.has(args.path)) { + return { path: args.path, namespace: 'node-builtin-stub' }; + } + return undefined; + }); + build.onLoad({ filter: /.*/, namespace: 'node-builtin-stub' }, () => ({ + // Empty CommonJS module: `import x from 'fs'` -> {}, named imports + // resolve to undefined without a build-time error (parity with + // webpack's `fs: false` fallback). + contents: 'module.exports = {};', + loader: 'js', + })); + }, +}; + const commonBuildOptions = { bundle: true, format: 'esm', @@ -63,22 +96,35 @@ const commonBuildOptions = { banner: { js: 'import { createRequire as __createRequire } from "module";\nconst require = __createRequire(import.meta.url);', }, - } : {}), + } : { + // Browser builds stub Node builtins to empty modules instead of leaving + // bare `import "fs"` in the output. + plugins: [stubNodeBuiltinsPlugin], + }), }; -esbuild.buildSync({ - ...commonBuildOptions, - entryPoints: [entryPoint], - outfile, -}); - -// For packages with dayjs-setup, also emit it as a separate ESM file so the -// sideEffects field in package.json can reference it without marking the entire -// index.mjs as side-effectful. -if (hasDayjsSetup) { - esbuild.buildSync({ +// The async build API is required because browser builds register an esbuild +// plugin (buildSync cannot use plugins). +async function main() { + await esbuild.build({ ...commonBuildOptions, - entryPoints: [path.join(packageDir, 'src', 'dayjs-setup.ts')], - outfile: path.join(packageDir, 'dist', 'esm', 'dayjs-setup.mjs'), + entryPoints: [entryPoint], + outfile, }); + + // For packages with dayjs-setup, also emit it as a separate ESM file so the + // sideEffects field in package.json can reference it without marking the + // entire index.mjs as side-effectful. + if (hasDayjsSetup) { + await esbuild.build({ + ...commonBuildOptions, + entryPoints: [path.join(packageDir, 'src', 'dayjs-setup.ts')], + outfile: path.join(packageDir, 'dist', 'esm', 'dayjs-setup.mjs'), + }); + } } + +main().catch(err => { + console.error(err); + process.exit(1); +}); From 14cb9816305c856b7e94163abee3a5cb68033839 Mon Sep 17 00:00:00 2001 From: mttrbrts Date: Fri, 28 Aug 2026 11:26:40 +0100 Subject: [PATCH 6/8] fix(concerto-core): export Decorated from public API Decorated is the base class of all decorated model elements (Declaration, Property, etc.) and was previously accessible only via the types/lib/introspect/decorated deep import path. With the exports field added in this PR, that path is no longer reachable. Exporting it from the main entry point is the correct fix. Signed-off-by: Matt Roberts --- packages/concerto-core/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/concerto-core/src/index.ts b/packages/concerto-core/src/index.ts index 79209d7719..8a08e4b998 100644 --- a/packages/concerto-core/src/index.ts +++ b/packages/concerto-core/src/index.ts @@ -16,6 +16,7 @@ import SecurityException = require("./securityexception"); import IllegalModelException = require("./introspect/illegalmodelexception"); import TypeNotFoundException = require("./typenotfoundexception"); import MetamodelException = require("./metamodelexception"); +import Decorated = require("./introspect/decorated"); import Decorator = require("./introspect/decorator"); import DecoratorFactory = require("./introspect/decoratorfactory"); import DecoratorManager = require("./decoratormanager"); @@ -63,8 +64,9 @@ export { IllegalModelException, TypeNotFoundException, MetamodelException, - Decorator, - DecoratorFactory, + Decorated, + Decorator, + DecoratorFactory, DecoratorManager, Declaration, ClassDeclaration, From cab5fc7d29b4307b09e636b13bc7add42f609bc5 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Fri, 28 Aug 2026 11:50:02 +0100 Subject: [PATCH 7/8] chore: remove stray issues.jsonl and add to .gitignore issues.jsonl is a local beads issue-tracker data file that was accidentally committed. Remove it and ignore it so it never re-appears in diffs. This fixes the license-check CI failure (the tool scanned the file and found no Apache 2.0 header). Signed-off-by: Matt Roberts --- .gitignore | 3 +++ issues.jsonl | 12 ------------ 2 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 issues.jsonl diff --git a/.gitignore b/.gitignore index 30a20a3fd2..d499a7fe17 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,6 @@ umd # TypeScript build folder dist + +# beads issue tracker data (local only) +issues.jsonl diff --git a/issues.jsonl b/issues.jsonl deleted file mode 100644 index 8829cecc8e..0000000000 --- a/issues.jsonl +++ /dev/null @@ -1,12 +0,0 @@ -{"id":"concerto-126","title":"Stage 0: Rebase fix/tree-shaking-sideeffects onto main + capture baseline","description":"Capture clean-main build+test baseline (oracle for 'tests pass unchanged'). Rebase branch (10 commits behind), resolve conflicts in root package.json/package-lock.json and per-package version fields. npm ci + ordered build on rebased branch. Post baseline test counts as notes.","notes":"Stage 0 COMPLETE (2026-08-28).\nBranch ts-rebase = origin/main + 3 commits: 374393dbf (Rishabh feat), ea7f35c44 (sideEffects fix), 3073809b8 (dayjs .mjs + DEVELOPERS.md build-order note). Rebase clean, no conflicts. Stray issues.jsonl beads artifact stripped from deliverable commit.\nSmoke build: npm ci + ordered 'npm run build' =\u003e STAGE0_EXIT=0. All 7 packages emit dist/esm/index.mjs. concerto-core emits dist/esm/dayjs-setup.mjs (26801 bytes, 5 extend refs =\u003e UTC/quarterOfYear/duration/minMax side effect intact). G1 preliminary PASS.\nBaseline oracle for G2: green main build+test captured earlier (exit 0, 0 failures) — verifier A diffs against it.\nWorktree: /tmp/concerto-ts-rebase","status":"closed","priority":1,"issue_type":"task","assignee":"mttrbrts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:49Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:07:40Z","started_at":"2026-08-28T09:00:19Z","closed_at":"2026-08-28T09:07:40Z","close_reason":"Stage 0 done: clean rebase, clean commit, smoke build green, all ESM artifacts present","dependency_count":0,"dependent_count":8,"comment_count":0} -{"id":"concerto-e2m","title":"Harden browser ESM build: stub Node builtins instead of emitting bare import \"fs\"/\"path\"","description":"PR #1263's browser-targeted ESM (dist/esm/index.mjs) still emits bare Node-builtin imports (import \"fs\" in concerto-core and concerto-util, import \"path\" in concerto-util) because scripts/build-esm.js externalizes builtinModules for all builds. This only resolves in downstream consumers that ship Node-polyfill/fallback infrastructure (concerto-playground via vite-plugin-node-polyfills, template-engine via webpack resolve.fallback). A stricter consumer (plain esbuild/rollup/Vite without polyfills) would fail with unresolved 'fs'/'path'. The existing webpack UMD build already avoids this by mapping fs/tls/net/child_process/os/path -\u003e false (empty stub). Fix: for browser builds only, stub Node builtins to empty modules via an esbuild plugin instead of externalizing them, achieving parity with the UMD. Keep externalizing builtins for the node-only linter build.","status":"in_progress","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T09:56:23Z","created_by":"Matt Roberts","updated_at":"2026-08-28T09:56:32Z","started_at":"2026-08-28T09:56:32Z","dependency_count":0,"dependent_count":0,"comment_count":0} -{"id":"concerto-yx7","title":"Address Copilot review feedback on PR #1263","description":"Two inline Copilot comments: (1) e2e/tests/browser-bundles.spec.ts imports Page as runtime value but uses it only as a type -\u003e type-only import. (2) scripts/build-esm.js injects createRequire banner unconditionally, leaking a Node-only 'module' import into browser-targeted .mjs outputs -\u003e gate banner to the node-only build. Verify browser ESM builds still succeed and emit no 'module' import.","notes":"Fixed in commit 63b4dd178, pushed to PR #1263 (fast-forward). (1) type-only Page import; (2) createRequire banner gated to node-only build. Verified: browser .mjs have 0 'module' imports + 0 require() calls; node .mjs keeps shim; Playwright 3/3. Replied to both Copilot threads.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T09:39:14Z","created_by":"Matt Roberts","updated_at":"2026-08-28T09:43:39Z","started_at":"2026-08-28T09:39:20Z","closed_at":"2026-08-28T09:43:39Z","close_reason":"Both Copilot review comments addressed, verified, pushed to PR #1263","dependency_count":0,"dependent_count":0,"comment_count":0} -{"id":"concerto-08k","title":"Spike E: per-export native-ESM migration measurement (leaf module) — GO/NO-GO","description":"Throwaway worktree. Migrate one low-fan-in concerto-core leaf module export=/import=require -\u003e native ESM. Measure single-export vs whole-index bundle bytes. Write GO/NO-GO memo. DISCARD worktree; nothing merges. Model: sonnet.","notes":"## Spike E — GO/NO-GO Memo: Native ESM Migration for Per-Export Tree-Shaking\n\n### Setup\n- Worktree: /tmp/wt-spike at commit 3073809b8 (rebased branch)\n- Leaf module tested: packages/concerto-core/src/securityexception.ts\n- Reason chosen: zero internal ./ requires, only one external dep (BaseException from @accordproject/concerto-util)\n- Measurement tool: esbuild --bundle --minify --platform=node\n\n---\n\n### BEFORE Baseline (current: esbuild bundle:true, CJS-in-ESM blob)\n\n| Import | Bundle size |\n|--------|------------|\n| 1 export (SecurityException only) | 595,862 bytes (596 KB) |\n| All exports (export * from index) | 596,715 bytes (597 KB) |\n| Delta (1 export vs all) | 853 bytes (0.14%) |\n\n**Interpretation:** Virtually no per-export tree-shaking. Importing one class vs the entire library differs by less than 1 KB because the whole concerto-core source (all 58 TS files + third-party deps) is pre-bundled into a single CJS-in-ESM blob using __commonJS/__esm wrappers. Bundlers cannot tree-shake inside this blob.\n\n---\n\n### AFTER Measurement (migrated securityexception.ts to native ESM, bundle:false)\n\nMigration performed: Changed securityexception.ts from:\n const { BaseException } = require('@accordproject/concerto-util'); ... export = SecurityException;\nTo:\n import { BaseException } from '@accordproject/concerto-util'; ... export { SecurityException };\n\nCompiled with esbuild bundle:false → 385-byte unbundled .mjs file with live import statement.\n\nConsumer bundler then tree-shakes the import chain (SecurityException → BaseException only).\n\n| Import | Bundle size |\n|--------|------------|\n| 1 export (SecurityException from unbundled .mjs) | 22,908 bytes (22 KB) |\n| Reduction vs BEFORE | **96.2%** (573 KB saved) |\n\nThe 22 KB is: SecurityException itself + the portion of @accordproject/concerto-util's bundled blob needed for BaseException. Note: concerto-util is ALSO a bundled CJS-in-ESM blob — if concerto-util were also migrated to native ESM, the after-bundle would be even smaller (BaseException is ~30 lines; full tree-shaken size would be \u003c1 KB).\n\n---\n\n### Migration Cost Assessment\n\n**Files requiring migration:** 58 total with export = / CJS require patterns.\n\n**Pure leaf files (no internal ./ requires at all):** 4 files:\n - securityexception.ts — trivial, migrated in spike (0 internal deps)\n - metamodelexception.ts — only external concerto-util\n - dayjs-setup.ts — external only \n - serializer/validationexception.ts — external only\n\n**Files with only const X = require('./internal') patterns:** ~38 more files\n - These use CJS require syntax, not TypeScript import = require\n - Each migrated file forces any file that requires IT to also migrate\n - The migration is a bottom-up topological traversal of the import graph\n\n**Migration pattern per file:**\n 1. Replace: const X = require('./foo') → import X from './foo.js'\n 2. Replace: const { X, Y } = require('@external') → import { X, Y } from '@external'\n 3. Replace: export = ClassName → export { ClassName }; export default ClassName;\n 4. If file uses globalize.ts (Globalize) — must migrate globalize.ts first\n\n**Blocker observed:** Most files depend on concerto-util which is ALSO a bundled CJS-in-ESM blob. This means even after migrating all 58 concerto-core files, tree-shaking INTO concerto-util would still be blocked. Full win requires migrating concerto-util too (estimated ~40 files in packages/concerto-util/src).\n\n**Estimated effort for concerto-core alone:** 58 files, topological order. Most files are mechanical find-replace. Complex files: basemodelmanager.ts (20 internal requires), serializer/jsonpopulator.ts (8+4 requires), factory.ts (10 internal requires). Estimate: 2-3 developer-days for an engineer familiar with the codebase, including test verification.\n\n**tsc TS1203 status:** Not hit during spike because esbuild was used (not tsc) for the after measurement. A tsc-based unbundled ESM build would require tsconfig with module: ESNext or ES2020, which IS supported by tsc — the TS1203 error only fires when you use export = WITH a module: es* setting. Removing export = (replacing with export {}) fully resolves TS1203.\n\n---\n\n### Build Path for Unbundled ESM\n\nReplace the current build:esm step (esbuild bundle:true → single index.mjs blob) with:\n - tsc --module ES2020 --moduleResolution bundler --outDir dist/esm (unbundled, one .mjs per .ts file)\n - OR esbuild with bundle:false and splitting:true\n - package.json exports map to individual files OR a thin re-export barrel\n\nThe build:esm script (scripts/build-esm.js) would be simplified — no bundling needed for the ESM path.\n\n---\n\n### VERDICT: GO (conditional on concerto-util co-migration)\n\n**GO** — the per-export tree-shaking benefit is massive and real: 96.2% bundle reduction for a leaf import. The migration pattern is mechanical and well-understood.\n\n**Condition:** Full wins require concerto-util to also migrate from its CJS-in-ESM bundle to native ESM. Without that, consumers still pull in all of concerto-util (~60 KB minified) even for leaf imports. With it, a SecurityException import would likely be \u003c2 KB total.\n\n**Recommended epic scope:**\n 1. Migrate concerto-util to native ESM (est. 1-2 days)\n 2. Migrate concerto-core to native ESM top-down (est. 2-3 days)\n 3. Update tsconfig.build.json: module → ES2020, moduleResolution → bundler\n 4. Replace build:esm esbuild bundle:true with tsc unbundled pass\n 5. Add exports map entries per module for deep imports (optional)\n 6. Verify all downstream packages (concerto-analysis, concerto-vocabulary, etc.) still build","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:53Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:18:01Z","started_at":"2026-08-28T09:11:31Z","closed_at":"2026-08-28T09:18:01Z","close_reason":"Spike complete: GO — 96.2% bundle reduction (596KB→23KB) for leaf import; 58-file migration is mechanical, conditional on concerto-util co-migration","dependencies":[{"issue_id":"concerto-08k","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:18Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":2,"comment_count":0} -{"id":"concerto-vnp","title":"Review nit: rename dayjs-setup ESM output to .mjs + update sideEffects/build-esm.js","description":"Package is not type:module, so dist/esm/dayjs-setup.js is parsed as CJS. Rename to .mjs, update sideEffects entry and scripts/build-esm.js outfile. Guarded by G6. Per Rishabh review comment on PR #1263.","status":"closed","priority":2,"issue_type":"task","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:52Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:06:39Z","closed_at":"2026-08-28T09:06:39Z","close_reason":"Done in commit 3073809b8: build-esm.js emits dist/esm/dayjs-setup.mjs; sideEffects updated to ./dist/esm/dayjs-setup.mjs","dependencies":[{"issue_id":"concerto-vnp","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:15Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":2,"comment_count":0} -{"id":"concerto-820","title":"Agent D: Playwright browser-bundle E2E (G4)","description":"Run e2e/tests/browser-bundles.spec.ts. Report pass/fail + trace on failure as notes. Model: haiku.","notes":"e2e location: /tmp/concerto-ts-rebase/e2e. Playwright: 3 passed / 0 failed. Browser bundles (CTO parser, core ModelManager, dayjs plugins) all load and function correctly in UMD format. VERDICT: PASS","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:51Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:13:32Z","started_at":"2026-08-28T09:11:05Z","closed_at":"2026-08-28T09:13:32Z","close_reason":"Closed","dependencies":[{"issue_id":"concerto-820","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:14Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} -{"id":"concerto-8qc","title":"Agent C: Non-breaking compat via packed tarballs (G5,G6)","description":"npm pack all 7 packages; install into scratch consumers: CJS require, ESM import, deep dist/* import, TS .d.ts resolution under node16/nodenext, UMD in browser context. dayjs plugins work in CJS+ESM. Record per-consumer results as notes. Model: sonnet.","notes":"G5(a) CJS: PASS. G5(b) ESM: PASS. G5(c) deep-import (dist/* escape hatch): PASS - require('@accordproject/concerto-core/dist/datetimeutil.js') resolves and returns dayjs obj. G5(d) node16 types: PASS (non-breaking) - identical 5 pre-existing TS8023 JSDoc @extends errors exist on published 4.2.0 AND PR branch; PR introduces zero new type errors. G6 dayjs CJS: PASS - fromJSON/toJSON DateTime round-trip works, UTC plugin active (output 2024-01-15T13:00:00.000+01:00). G6 dayjs ESM: PASS - same round-trip works via ESM index.mjs path. VERDICT: PASS","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:50Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:16:32Z","started_at":"2026-08-28T09:10:54Z","closed_at":"2026-08-28T09:16:32Z","close_reason":"Closed","dependencies":[{"issue_id":"concerto-8qc","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:13Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} -{"id":"concerto-un6","title":"Agent B: Rollup tree-shaking measurement harness (G3)","description":"Author+run Rollup + @rollup/plugin-node-resolve harness against dist/esm/*.mjs. Measure: util-only entry (assert excludes concerto-core, ~\u003c=120KB) vs ModelManager entry (~1.4-1.5MB). Record byte counts as notes. Model: sonnet.","notes":"util-only bundle: 22,503 bytes (22KB), contains concerto-core? NO (0 hits for ModelManager/IllegalModelException). ModelManager bundle: 579,052 bytes (565KB). Both bundles built cleanly with rollup+terser ESM. Thresholds: util well under 120KB cap; core bundle is large as expected. VERDICT: PASS - package-level tree-shaking works; importing only concerto-util does not pull in concerto-core code.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:50Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:12:11Z","started_at":"2026-08-28T09:10:28Z","closed_at":"2026-08-28T09:12:11Z","close_reason":"G3 PASS: util-only bundle=22KB (no concerto-core symbols), ModelManager bundle=565KB. Package-level tree-shaking verified via rollup+terser ESM bundles.","dependencies":[{"issue_id":"concerto-un6","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:13Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} -{"id":"concerto-isg","title":"Agent A: Build + full test verification vs baseline (G1,G2,G6)","description":"In isolated worktree on rebased branch: npm ci, ordered build (all 7 packages emit CJS/ESM/UMD; core emits dist/esm/dayjs-setup.mjs). Run full test suite; compare pass set to baseline. Assert git diff shows ZERO changes to *.spec.ts/test/**. dayjs setCurrentTime works. Post results as notes; close if green, reopen with details if red. Model: haiku.","notes":"**VERIFICATION PASS**\n\nG1 (ESM artifacts): PASS\n - All 7 packages emit dist/esm/index.mjs ✓\n - concerto-core emits dist/esm/dayjs-setup.mjs ✓\n\nG2 (Test suite \u0026 file integrity): PASS\n - Build exit code: 0 ✓\n - Total tests: 1,679 passing, 0 failing (concerto-core: 1,276p; concerto-analysis: 163p; concerto-util: 151p; concerto-vocabulary: 89p; concerto-linter: 18p; linter-ruleset: 19p)\n - Test file diff: 1 ADDED (e2e/tests/browser-bundles.spec.ts) — no modifications/deletions ✓\n\nG6 (dayjs/DateTimeUtil): PASS\n - DateTimeUtil suite fully green (dayjs conversion tests included and passing) ✓\n\n**VERDICT: PASS** — Branch 3073809b8 matches baseline oracle (main). All gates met.","status":"closed","priority":2,"issue_type":"task","assignee":"Matt Roberts","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:49Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:13:00Z","started_at":"2026-08-28T09:10:14Z","closed_at":"2026-08-28T09:13:00Z","close_reason":"G1+G2+G6 all PASS: ESM artifacts present, 1679 tests green (0 failing), test files clean (only 1 new file added), dayjs suite passing. Rebased branch 3073809b8 verified against main baseline.","dependencies":[{"issue_id":"concerto-isg","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:12Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-isg","depends_on_id":"concerto-vnp","type":"blocks","created_at":"2026-08-28T09:59:18Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":2,"dependent_count":1,"comment_count":0} -{"id":"concerto-a6y","title":"Epic: Complete tree-shaking support (#1261) — land PR #1263","description":"Refresh and land PR #1263 (fix/tree-shaking-sideeffects) on current main. Package-level tree-shaking + additive ESM + browser-bundle validation, non-breaking, all existing tests pass unchanged. Plus a throwaway spike measuring per-export migration. See plan-issue-1261-tree-shaking.md. GitHub issue: https://github.com/accordproject/concerto/issues/1261","notes":"All acceptance gates verified 2026-08-28 on branch ts-rebase (=fix/tree-shaking-sideeffects rebased on main, HEAD 3073809b8):\nG1 build/artifacts PASS · G2 tests 1679 pass/0 fail, no existing-test edits PASS · G3 pkg tree-shaking (util-only 22.5KB, no core; ModelManager 579KB) PASS · G4 Playwright 3/3 PASS · G5 compat CJS/ESM/deep/node16-types PASS (only 5 pre-existing TS8023 errors, no new) · G6 dayjs both module systems PASS · G7 spike GO-conditional (1 export 595,862-\u003e22,908 B, 96.2%).\nREMAINING: force-push ts-rebase -\u003e PR #1263 branch is BLOCKED pending explicit human approval (destructive public-branch push). Then update PR body + human merge. DO NOT auto-merge.","status":"open","priority":2,"issue_type":"feature","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:14Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:25:35Z","dependencies":[{"issue_id":"concerto-a6y","depends_on_id":"concerto-08k","type":"blocks","created_at":"2026-08-28T09:59:26Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:21Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-820","type":"blocks","created_at":"2026-08-28T09:59:24Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-8qc","type":"blocks","created_at":"2026-08-28T09:59:24Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-isg","type":"blocks","created_at":"2026-08-28T09:59:22Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-j93","type":"blocks","created_at":"2026-08-28T09:59:26Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-un6","type":"blocks","created_at":"2026-08-28T09:59:23Z","created_by":"mttrbrts","metadata":"{}"},{"issue_id":"concerto-a6y","depends_on_id":"concerto-vnp","type":"blocks","created_at":"2026-08-28T09:59:25Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":8,"dependent_count":0,"comment_count":0} -{"id":"concerto-334","title":"Follow-up Epic: full concerto-core native-ESM migration (per-export tree-shaking)","description":"Migrate all 58 concerto-core/src files from export=/import=require to native ESM so bundlers can drop unused exports. Blocked on Spike E findings. Larger refactor, separate PR, stresses 'tests pass unchanged'.","notes":"GitHub issue: https://github.com/accordproject/concerto/issues/1304 (created 2026-08-28)","status":"open","priority":3,"issue_type":"feature","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:53Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:35:50Z","dependencies":[{"issue_id":"concerto-334","depends_on_id":"concerto-08k","type":"blocks","created_at":"2026-08-28T09:59:19Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0} -{"id":"concerto-j93","title":"Review nit: document local build-order gotcha in DEVELOPERS.md","description":"Building concerto-core alone fails until concerto-cto ESM dist exists (exports.import resolves symlink to dist/esm/index.mjs before build). Add note; confirm build:ordered handles it in CI.","status":"closed","priority":3,"issue_type":"task","owner":"code@rbrts.uk","created_at":"2026-08-28T08:58:52Z","created_by":"mttrbrts","updated_at":"2026-08-28T09:06:43Z","closed_at":"2026-08-28T09:06:43Z","close_reason":"Done in commit 3073809b8: DEVELOPERS.md documents mandatory ordered monorepo build","dependencies":[{"issue_id":"concerto-j93","depends_on_id":"concerto-126","type":"blocks","created_at":"2026-08-28T09:59:17Z","created_by":"mttrbrts","metadata":"{}"}],"dependency_count":1,"dependent_count":1,"comment_count":0} From f452b4c62d60fec09ec111a80e803bbcda6d4c94 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Fri, 28 Aug 2026 12:40:39 +0100 Subject: [PATCH 8/8] fix(concerto): map ./types/* in exports to preserve deep-import compat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exports field added for tree-shaking encapsulated each package to ./dist/* + ./package.json, which silently made the published ./types/* declaration tree (shipped outside dist/) unreachable under node16/nodenext and bundler resolution — a resolution regression for any consumer deep- importing those supplemental .d.ts paths, which resolved fine before the exports field existed. Map ./types/* alongside ./dist/* on the four packages that publish a types/ tree (util, cto, core, vocabulary) so the pre-existing deep-import surface is preserved. Verified with a node16-resolution tsc probe that a types/ deep-import now resolves (TS2307 before -> clean after). Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- packages/concerto-core/package.json | 3 ++- packages/concerto-cto/package.json | 3 ++- packages/concerto-util/package.json | 3 ++- packages/concerto-vocabulary/package.json | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/concerto-core/package.json b/packages/concerto-core/package.json index 0d6cc7e39b..4183e660bc 100644 --- a/packages/concerto-core/package.json +++ b/packages/concerto-core/package.json @@ -168,7 +168,8 @@ "require": "./dist/index.js" }, "./package.json": "./package.json", - "./dist/*": "./dist/*" + "./dist/*": "./dist/*", + "./types/*": "./types/*" }, "sideEffects": [ "./dist/dayjs-setup.js", diff --git a/packages/concerto-cto/package.json b/packages/concerto-cto/package.json index a576c90628..2d7217b0a0 100644 --- a/packages/concerto-cto/package.json +++ b/packages/concerto-cto/package.json @@ -148,7 +148,8 @@ "require": "./dist/index.js" }, "./package.json": "./package.json", - "./dist/*": "./dist/*" + "./dist/*": "./dist/*", + "./types/*": "./types/*" }, "sideEffects": false } diff --git a/packages/concerto-util/package.json b/packages/concerto-util/package.json index 1c8be492a2..5cc96ed234 100644 --- a/packages/concerto-util/package.json +++ b/packages/concerto-util/package.json @@ -139,7 +139,8 @@ "require": "./dist/index.js" }, "./package.json": "./package.json", - "./dist/*": "./dist/*" + "./dist/*": "./dist/*", + "./types/*": "./types/*" }, "sideEffects": false } diff --git a/packages/concerto-vocabulary/package.json b/packages/concerto-vocabulary/package.json index 83df7e90b6..4f50aba471 100644 --- a/packages/concerto-vocabulary/package.json +++ b/packages/concerto-vocabulary/package.json @@ -136,7 +136,8 @@ "require": "./dist/index.js" }, "./package.json": "./package.json", - "./dist/*": "./dist/*" + "./dist/*": "./dist/*", + "./types/*": "./types/*" }, "sideEffects": false }