Migrate out of typesVersions in package.json and cleanup (#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.
This commit is contained in:
Timothee Guerin 2023-10-04 15:16:08 -07:00 коммит произвёл GitHub
Родитель 0c4a80899d
Коммит e02b74a876
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
36 изменённых файлов: 263 добавлений и 137 удалений

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/bundler",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/bundler"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/html-program-viewer",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/html-program-viewer"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/http",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/http"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/internal-build-utils",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/internal-build-utils"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/json-schema",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/json-schema"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/library-linter",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/library-linter"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/lint",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/lint"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/openapi"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/openapi3",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/openapi3"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/rest",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/rest"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/versioning",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "@typespec/versioning"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "tmlanguage-generator",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "patch"
}
],
"packageName": "tmlanguage-generator"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "typespec-vs",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "typespec-vs"
}

Просмотреть файл

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "typespec-vscode",
"comment": "`TypeScript` use `types` entry under `exports` of `package.json` instead of legacy `typesVersions` to provide the definition files",
"type": "none"
}
],
"packageName": "typespec-vscode"
}

Просмотреть файл

@ -226,13 +226,13 @@ export const MyTestLibrary = createTestLibrary({
// ...
"main": "dist/src/index.js",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": ["./dist/src/index.d.ts"],
"testing": ["./dist/src/testing/index.d.ts"]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
}
}

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec linter rules to enforce best practices.",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "Package to bundle a typespec library.",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -18,7 +18,12 @@ export interface TypeSpecBundleDefinition {
path: string;
main: string;
packageJson: PackageJson;
exports: Record<string, string>;
exports: Record<string, string | ExportData>;
}
export interface ExportData {
default: string;
types?: string;
}
export interface TypeSpecBundle {
@ -148,7 +153,10 @@ async function createRollupConfig(definition: TypeSpecBundleDefinition): Promise
const extraEntry = Object.fromEntries(
Object.entries(definition.exports).map(([key, value]) => {
return [key.replace("./", ""), normalizePath(resolve(libraryPath, value))];
return [
key.replace("./", ""),
normalizePath(resolve(libraryPath, getExportEntryPoint(value))),
];
})
);
return {
@ -195,15 +203,19 @@ async function generateTypeSpecBundle(
files: output
.filter((x): x is OutputChunk => "code" in x)
.map((chunk) => {
const entry = definition.exports[basename(chunk.fileName)];
return {
filename: chunk.fileName,
content: chunk.code,
export: definition.exports[basename(chunk.fileName)],
export: entry ? getExportEntryPoint(entry) : undefined,
};
}),
};
}
function getExportEntryPoint(value: string | ExportData) {
return typeof value === "string" ? value : value.default;
}
async function readLibraryPackageJson(path: string): Promise<PackageJson> {
const file = await readFile(join(path, "package.json"));
return JSON.parse(file.toString());

Просмотреть файл

@ -5,7 +5,7 @@
"author": "Microsoft Corporation",
"license": "MIT",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/typespec.git"
@ -21,31 +21,27 @@
"main": "dist/src/index.js",
"tspMain": "lib/main.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js",
"./module-resolver": "./dist/src/core/module-resolver.js",
"./emitter-framework": "./dist/src/emitter-framework/index.js"
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
},
"./module-resolver": {
"default": "./dist/src/core/module-resolver.js",
"types": "./dist/src/core/module-resolver.d.ts"
},
"./emitter-framework": {
"default": "./dist/src/emitter-framework/index.js",
"types": "./dist/src/emitter-framework/index.d.ts"
}
},
"browser": {
"./dist/src/core/node-host.js": "./dist/src/core/node-host.browser.js",
"./dist/src/core/logger/console-sink.js": "./dist/src/core/logger/console-sink.browser.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
],
"module-resolver": [
"./dist/src/core/module-resolver.d.ts"
],
"emitter-framework": [
"./dist/src/emitter-framework/index.d.ts"
]
}
},
"engines": {
"node": ">=16.0.0"
},

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec library for emitting an html view of the program.",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -19,17 +19,13 @@
"type": "module",
"main": "dist/src/index.js",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"tspMain": "dist/src/index.js",

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec HTTP protocol binding",
"homepage": "https://github.com/microsoft/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "lib/http.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "Internal library to TypeSpec providing helpers to build.",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec library for emitting TypeSpec to JSON Schema and converting JSON Schema to TypeSpec",
"homepage": "https://github.com/microsoft/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec library for linting another library.",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -19,17 +19,13 @@
"type": "module",
"main": "dist/src/index.js",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"tspMain": "dist/src/index.js",

Просмотреть файл

@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "dist/src/index.js",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {

Просмотреть файл

@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "lib/main.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec library for emitting OpenAPI 3.0 from the TypeSpec REST protocol binding",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "lib/main.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec REST protocol binding",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "lib/rest.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {

Просмотреть файл

@ -5,7 +5,7 @@
"author": "Microsoft Corporation",
"description": "Samples for TypeSpec",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/readme.md",
"readme": "https://github.com/microsoft/typespec/blob/main/readme.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -5,7 +5,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec Language Specification Source Code",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/typespec/issues"

Просмотреть файл

@ -3,8 +3,8 @@
"version": "0.4.4",
"author": "Microsoft Corporation",
"description": "Helper library to generate TextMate syntax highlighting tmLanguage files.",
"homepage": "https://github.com/microsoft/typespec/tree/master/packages/tmlanguage-generator",
"readme": "https://github.com/microsoft/typespec/blob/master/packages/tmlanguage-generator/README.md",
"homepage": "https://github.com/microsoft/typespec/tree/main/packages/tmlanguage-generator",
"readme": "https://github.com/microsoft/typespec/blob/main/packages/tmlanguage-generator/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -4,7 +4,7 @@
"version": "0.48.0",
"description": "TypeSpec Language Support for Visual Studio",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec Language Support for VS Code",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",

Просмотреть файл

@ -5,8 +5,8 @@
"outDir": "dist-dev",
"rootDir": ".",
"tsBuildInfoFile": "temp/tsconfig.tsbuildinfo",
"module": "CommonJS",
"moduleResolution": "Node",
"module": "ES2022",
"moduleResolution": "Bundler",
"skipLibCheck": true,
"types": ["node", "mocha"]
},

Просмотреть файл

@ -4,7 +4,7 @@
"author": "Microsoft Corporation",
"description": "TypeSpec library for declaring and emitting versioned APIs",
"homepage": "https://microsoft.github.io/typespec",
"readme": "https://github.com/microsoft/typespec/blob/master/README.md",
"readme": "https://github.com/microsoft/typespec/blob/main/README.md",
"license": "MIT",
"repository": {
"type": "git",
@ -20,17 +20,13 @@
"main": "dist/src/index.js",
"tspMain": "lib/versioning.tsp",
"exports": {
".": "./dist/src/index.js",
"./testing": "./dist/src/testing/index.js"
},
"typesVersions": {
"*": {
"*": [
"./dist/src/index.d.ts"
],
"testing": [
"./dist/src/testing/index.d.ts"
]
".": {
"default": "./dist/src/index.js",
"types": "./dist/src/index.d.ts"
},
"./testing": {
"default": "./dist/src/testing/index.js",
"types": "./dist/src/testing/index.d.ts"
}
},
"engines": {