Skip to content

Commit e02b74a

Browse files
Migrate out of typesVersions in package.json and cleanup (microsoft#2488)
Same pr in typespec-azure https://github.com/Azure/typespec-azure/pull/3641 Migrate to use the `types` entry under `exports` instead of hte legacy typesVersions. This was a leftover to when es modules where not completely supported in typescript and using typesVersions was a workaround.
1 parent 0c4a808 commit e02b74a

36 files changed

+263
-137
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/bundler",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/bundler"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/compiler",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/compiler"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/html-program-viewer",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/html-program-viewer"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/http",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/http"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/internal-build-utils",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/internal-build-utils"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/json-schema",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/json-schema"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/library-linter",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/library-linter"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/lint",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/lint"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/openapi",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/openapi"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/openapi3",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/openapi3"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/rest",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/rest"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@typespec/versioning",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@typespec/versioning"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "tmlanguage-generator",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "tmlanguage-generator"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "typespec-vs",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "typespec-vs"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "typespec-vscode",
5+
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "typespec-vscode"
10+
}

docs/extending-typespec/basics.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ export const MyTestLibrary = createTestLibrary({
226226
// ...
227227
"main": "dist/src/index.js",
228228
"exports": {
229-
".": "./dist/src/index.js",
230-
"./testing": "./dist/src/testing/index.js"
231-
},
232-
"typesVersions": {
233-
"*": {
234-
"*": ["./dist/src/index.d.ts"],
235-
"testing": ["./dist/src/testing/index.d.ts"]
229+
".": {
230+
"default": "./dist/src/index.js",
231+
"types": "./dist/src/index.d.ts"
232+
},
233+
"./testing": {
234+
"default": "./dist/src/testing/index.js",
235+
"types": "./dist/src/testing/index.d.ts"
236236
}
237237
}
238238
}

packages/best-practices/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Microsoft Corporation",
55
"description": "TypeSpec linter rules to enforce best practices.",
66
"homepage": "https://microsoft.github.io/typespec",
7-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
7+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
88
"license": "MIT",
99
"repository": {
1010
"type": "git",

packages/bundler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Microsoft Corporation",
55
"description": "Package to bundle a typespec library.",
66
"homepage": "https://microsoft.github.io/typespec",
7-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
7+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
88
"license": "MIT",
99
"repository": {
1010
"type": "git",

packages/bundler/src/bundler.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ export interface TypeSpecBundleDefinition {
1818
path: string;
1919
main: string;
2020
packageJson: PackageJson;
21-
exports: Record<string, string>;
21+
exports: Record<string, string | ExportData>;
22+
}
23+
24+
export interface ExportData {
25+
default: string;
26+
types?: string;
2227
}
2328

2429
export interface TypeSpecBundle {
@@ -148,7 +153,10 @@ async function createRollupConfig(definition: TypeSpecBundleDefinition): Promise
148153

149154
const extraEntry = Object.fromEntries(
150155
Object.entries(definition.exports).map(([key, value]) => {
151-
return [key.replace("./", ""), normalizePath(resolve(libraryPath, value))];
156+
return [
157+
key.replace("./", ""),
158+
normalizePath(resolve(libraryPath, getExportEntryPoint(value))),
159+
];
152160
})
153161
);
154162
return {
@@ -195,15 +203,19 @@ async function generateTypeSpecBundle(
195203
files: output
196204
.filter((x): x is OutputChunk => "code" in x)
197205
.map((chunk) => {
206+
const entry = definition.exports[basename(chunk.fileName)];
198207
return {
199208
filename: chunk.fileName,
200209
content: chunk.code,
201-
export: definition.exports[basename(chunk.fileName)],
210+
export: entry ? getExportEntryPoint(entry) : undefined,
202211
};
203212
}),
204213
};
205214
}
206215

216+
function getExportEntryPoint(value: string | ExportData) {
217+
return typeof value === "string" ? value : value.default;
218+
}
207219
async function readLibraryPackageJson(path: string): Promise<PackageJson> {
208220
const file = await readFile(join(path, "package.json"));
209221
return JSON.parse(file.toString());

packages/compiler/package.json

+17-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Microsoft Corporation",
66
"license": "MIT",
77
"homepage": "https://microsoft.github.io/typespec",
8-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
8+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
99
"repository": {
1010
"type": "git",
1111
"url": "git+https://github.com/microsoft/typespec.git"
@@ -21,31 +21,27 @@
2121
"main": "dist/src/index.js",
2222
"tspMain": "lib/main.tsp",
2323
"exports": {
24-
".": "./dist/src/index.js",
25-
"./testing": "./dist/src/testing/index.js",
26-
"./module-resolver": "./dist/src/core/module-resolver.js",
27-
"./emitter-framework": "./dist/src/emitter-framework/index.js"
24+
".": {
25+
"default": "./dist/src/index.js",
26+
"types": "./dist/src/index.d.ts"
27+
},
28+
"./testing": {
29+
"default": "./dist/src/testing/index.js",
30+
"types": "./dist/src/testing/index.d.ts"
31+
},
32+
"./module-resolver": {
33+
"default": "./dist/src/core/module-resolver.js",
34+
"types": "./dist/src/core/module-resolver.d.ts"
35+
},
36+
"./emitter-framework": {
37+
"default": "./dist/src/emitter-framework/index.js",
38+
"types": "./dist/src/emitter-framework/index.d.ts"
39+
}
2840
},
2941
"browser": {
3042
"./dist/src/core/node-host.js": "./dist/src/core/node-host.browser.js",
3143
"./dist/src/core/logger/console-sink.js": "./dist/src/core/logger/console-sink.browser.js"
3244
},
33-
"typesVersions": {
34-
"*": {
35-
"*": [
36-
"./dist/src/index.d.ts"
37-
],
38-
"testing": [
39-
"./dist/src/testing/index.d.ts"
40-
],
41-
"module-resolver": [
42-
"./dist/src/core/module-resolver.d.ts"
43-
],
44-
"emitter-framework": [
45-
"./dist/src/emitter-framework/index.d.ts"
46-
]
47-
}
48-
},
4945
"engines": {
5046
"node": ">=16.0.0"
5147
},

packages/html-program-viewer/package.json

+8-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Microsoft Corporation",
55
"description": "TypeSpec library for emitting an html view of the program.",
66
"homepage": "https://microsoft.github.io/typespec",
7-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
7+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
88
"license": "MIT",
99
"repository": {
1010
"type": "git",
@@ -19,17 +19,13 @@
1919
"type": "module",
2020
"main": "dist/src/index.js",
2121
"exports": {
22-
".": "./dist/src/index.js",
23-
"./testing": "./dist/src/testing/index.js"
24-
},
25-
"typesVersions": {
26-
"*": {
27-
"*": [
28-
"./dist/src/index.d.ts"
29-
],
30-
"testing": [
31-
"./dist/src/testing/index.d.ts"
32-
]
22+
".": {
23+
"default": "./dist/src/index.js",
24+
"types": "./dist/src/index.d.ts"
25+
},
26+
"./testing": {
27+
"default": "./dist/src/testing/index.js",
28+
"types": "./dist/src/testing/index.d.ts"
3329
}
3430
},
3531
"tspMain": "dist/src/index.js",

packages/http/package.json

+8-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Microsoft Corporation",
55
"description": "TypeSpec HTTP protocol binding",
66
"homepage": "https://github.com/microsoft/typespec",
7-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
7+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
88
"license": "MIT",
99
"repository": {
1010
"type": "git",
@@ -20,17 +20,13 @@
2020
"main": "dist/src/index.js",
2121
"tspMain": "lib/http.tsp",
2222
"exports": {
23-
".": "./dist/src/index.js",
24-
"./testing": "./dist/src/testing/index.js"
25-
},
26-
"typesVersions": {
27-
"*": {
28-
"*": [
29-
"./dist/src/index.d.ts"
30-
],
31-
"testing": [
32-
"./dist/src/testing/index.d.ts"
33-
]
23+
".": {
24+
"default": "./dist/src/index.js",
25+
"types": "./dist/src/index.d.ts"
26+
},
27+
"./testing": {
28+
"default": "./dist/src/testing/index.js",
29+
"types": "./dist/src/testing/index.d.ts"
3430
}
3531
},
3632
"engines": {

packages/internal-build-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"author": "Microsoft Corporation",
55
"description": "Internal library to TypeSpec providing helpers to build.",
66
"homepage": "https://microsoft.github.io/typespec",
7-
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
7+
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
88
"license": "MIT",
99
"repository": {
1010
"type": "git",

0 commit comments

Comments
 (0)