Skip to content

Commit

Permalink
Migrate out of typesVersions in package.json and cleanup (#2560)
Browse files Browse the repository at this point in the history
Re-Reverts #2554

Making this pr for next release

Co-authored-by: Mark Cowlishaw <[email protected]>
  • Loading branch information
timotheeguerin and markcowl authored Nov 6, 2023
1 parent e3e619f commit 0ca049c
Show file tree
Hide file tree
Showing 37 changed files with 263 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
10 changes: 10 additions & 0 deletions common/changes/typespec-vs/pkgjson-cleanup_2023-09-26-19-09.json
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 7 additions & 7 deletions docs/extending-typespec/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/best-practices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 15 additions & 3 deletions packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 {
Expand Down Expand Up @@ -163,7 +168,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 {
Expand Down Expand Up @@ -211,15 +219,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());
Expand Down
38 changes: 17 additions & 21 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": ">=18.0.0"
},
Expand Down
20 changes: 8 additions & 12 deletions packages/html-program-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 0ca049c

Please sign in to comment.