Skip to content

Commit 26f01bd

Browse files
authored
build(client-container-runtime-definitions): add ESM support (#20160)
and make type only package. While a type only package, if any types depend on other packages that are dual emitted, then this must also be dual emitted. Otherwise, diamond references may result in using both `require` and `import` types from a referenced package that tsc will flag as incompatible (good thing).
1 parent 852a80f commit 26f01bd

File tree

8 files changed

+77
-38
lines changed

8 files changed

+77
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"extends": "../../../common/build/build-common/api-extractor-base.cjs.primary.json",
4+
// CJS is actually secondary; so, no report.
5+
"apiReport": {
6+
"enabled": false
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3-
"extends": "../../../common/build/build-common/api-extractor-lint.json"
3+
"extends": "../../../common/build/build-common/api-extractor-lint.esm.primary.json"
44
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3-
"extends": "../../../common/build/build-common/api-extractor-base.json"
3+
"extends": "../../../common/build/build-common/api-extractor-base.esm.primary.json"
44
}

packages/runtime/container-runtime-definitions/package.json

+38-21
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,68 @@
1111
"license": "MIT",
1212
"author": "Microsoft and contributors",
1313
"sideEffects": false,
14-
"type": "commonjs",
14+
"type": "module",
1515
"exports": {
1616
".": {
17-
"types": "./dist/index.d.ts",
18-
"default": "./dist/index.js"
17+
"import": {
18+
"types": "./lib/index.d.ts"
19+
},
20+
"require": {
21+
"types": "./dist/index.d.ts"
22+
}
1923
},
20-
"./alpha": {
21-
"types": "./dist/container-runtime-definitions-alpha.d.ts",
22-
"default": "./dist/index.js"
24+
"./public": {
25+
"import": {
26+
"types": "./lib/container-runtime-definitions-public.d.ts"
27+
},
28+
"require": {
29+
"types": "./dist/container-runtime-definitions-public.d.ts"
30+
}
2331
},
24-
"./beta": {
25-
"types": "./dist/container-runtime-definitions-beta.d.ts",
26-
"default": "./dist/index.js"
32+
"./alpha": {
33+
"import": {
34+
"types": "./lib/container-runtime-definitions-alpha.d.ts"
35+
},
36+
"require": {
37+
"types": "./dist/container-runtime-definitions-alpha.d.ts"
38+
}
2739
},
2840
"./internal": {
29-
"types": "./dist/index.d.ts",
30-
"default": "./dist/index.js"
31-
},
32-
"./public": {
33-
"types": "./dist/container-runtime-definitions-public.d.ts",
34-
"default": "./dist/index.js"
41+
"import": {
42+
"types": "./lib/index.d.ts"
43+
},
44+
"require": {
45+
"types": "./dist/index.d.ts"
46+
}
3547
}
3648
},
37-
"main": "dist/index.js",
49+
"main": "",
3850
"types": "dist/index.d.ts",
3951
"scripts": {
4052
"api": "fluid-build . --task api",
41-
"api-extractor:commonjs": "api-extractor run --local",
53+
"api-extractor:commonjs": "api-extractor run --config ./api-extractor-cjs.json",
54+
"api-extractor:esnext": "api-extractor run --local",
4255
"build": "fluid-build . --task build",
4356
"build:compile": "fluid-build . --task compile",
4457
"build:docs": "fluid-build . --task api",
45-
"build:test": "tsc --project ./src/test/tsconfig.json",
58+
"build:esnext": "tsc --project ./tsconfig.json",
59+
"build:test": "npm run build:test:esm && npm run build:test:cjs",
60+
"build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
61+
"build:test:esm": "tsc --project ./src/test/tsconfig.json",
4662
"check:are-the-types-wrong": "attw --pack . --entrypoints .",
4763
"check:biome": "biome check .",
4864
"check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
4965
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
5066
"ci:build:docs": "api-extractor run",
51-
"clean": "rimraf --glob dist \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp",
67+
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp",
5268
"eslint": "eslint --format stylish src",
5369
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
5470
"format": "fluid-build --task format .",
5571
"format:biome": "biome check --apply .",
5672
"format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
5773
"lint": "fluid-build . --task lint",
5874
"lint:fix": "fluid-build . --task eslint:fix --task format",
59-
"tsc": "tsc",
75+
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
6076
"typetests:gen": "fluid-type-test-generator",
6177
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
6278
},
@@ -87,7 +103,8 @@
87103
"build:docs": {
88104
"dependsOn": [
89105
"...",
90-
"api-extractor:commonjs"
106+
"api-extractor:commonjs",
107+
"api-extractor:esnext"
91108
],
92109
"script": false
93110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// This config must be used in a "type": "commonjs" environment. (Use fluid-tsc commonjs.)
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../../dist/test",
6+
},
7+
"references": [
8+
{
9+
"path": "../../tsconfig.cjs.json",
10+
},
11+
],
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
{
2-
"extends": [
3-
"../../../../../common/build/build-common/tsconfig.base.json",
4-
"../../../../../common/build/build-common/tsconfig.esm-only.json",
5-
],
2+
"extends": "../../../../../common/build/build-common/tsconfig.test.node16.json",
63
"include": ["./**/*"],
7-
"references": [
8-
{
9-
"path": "../..",
10-
},
11-
],
124
"compilerOptions": {
135
"rootDir": "./",
14-
"outDir": "../../dist/test",
6+
"outDir": "../../lib/test",
157
"types": [],
168
"noEmit": true,
179
},
10+
"references": [
11+
{
12+
"path": "../..",
13+
},
14+
],
1815
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// This config must be used in a "type": "commonjs" environment. (Use fluid-tsc commonjs.)
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "./dist",
6+
},
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{
2-
"extends": [
3-
"../../../common/build/build-common/tsconfig.base.json",
4-
"../../../common/build/build-common/tsconfig.esm-only.json",
5-
],
2+
"extends": "../../../common/build/build-common/tsconfig.node16.json",
63
"include": ["src/**/*"],
74
"exclude": ["src/test/**/*"],
85
"compilerOptions": {
96
"rootDir": "./src",
10-
"outDir": "./dist",
7+
"outDir": "./lib",
8+
"emitDeclarationOnly": true,
119
},
1210
}

0 commit comments

Comments
 (0)