Skip to content

Commit

Permalink
Undo rootdir change (#144)
Browse files Browse the repository at this point in the history
* Undo rootdir change

* Add unit test to protect against lack of typesaftey for package.json

* Include missing file
  • Loading branch information
ericanderson authored Mar 22, 2024
1 parent 2c35b03 commit 8da7dd8
Show file tree
Hide file tree
Showing 38 changed files with 216 additions and 113 deletions.
10 changes: 5 additions & 5 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ function getTsconfigOptions(baseTsconfigPath, opts) {
extends: baseTsconfigPath,

compilerOptions: {
rootDir: ".",
rootDir: "src",
outDir: "build/types",
composite: true,
},
include: ["./src/**/*", ".eslintrc.cjs", "package.json"],
include: ["./src/**/*", ".eslintrc.cjs"],
...(opts.customTsconfigExcludes
? { exclude: opts.customTsconfigExcludes ?? [] }
: {}),
Expand Down Expand Up @@ -137,12 +137,12 @@ function standardPackageRules(shared, options) {
entries: {
exports: {
".": {
types: "./build/types/src/index.d.ts",
types: "./build/types/index.d.ts",
import: "./build/js/index.mjs",
require: `./build/js/index.${options.legacy ? "" : "c"}js`,
},
"./*": {
types: "./build/types/src/public/*.d.ts",
types: "./build/types/public/*.d.ts",
import: "./build/js/public/*.mjs",
require: `./build/js/public/*.${options.legacy ? "" : "c"}js`,
},
Expand All @@ -164,7 +164,7 @@ function standardPackageRules(shared, options) {

main: `./build/js/index.${options.legacy ? "" : "c"}js`,
module: "./build/js/index.mjs",
types: "./build/types/src/index.d.ts",
types: "./build/types/index.d.ts",
},
},
}),
Expand Down
6 changes: 3 additions & 3 deletions examples-extra/basic/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
},
"exports": {
".": {
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"import": "./build/js/index.mjs",
"require": "./build/js/index.cjs"
},
"./*": {
"types": "./build/types/src/public/*.d.ts",
"types": "./build/types/public/*.d.ts",
"import": "./build/js/public/*.mjs",
"require": "./build/js/public/*.cjs"
}
Expand Down Expand Up @@ -53,6 +53,6 @@
],
"main": "./build/js/index.cjs",
"module": "./build/js/index.mjs",
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"type": "module"
}
5 changes: 2 additions & 3 deletions examples-extra/basic/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "../../../monorepo/tsconfig/tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "src",
"outDir": "build/types",
"composite": true
},
"include": [
"./src/**/*",
".eslintrc.cjs",
"package.json"
".eslintrc.cjs"
],
"references": [
{
Expand Down
6 changes: 3 additions & 3 deletions examples-extra/basic/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"exports": {
".": {
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"import": "./build/js/index.mjs",
"require": "./build/js/index.cjs"
},
"./*": {
"types": "./build/types/src/public/*.d.ts",
"types": "./build/types/public/*.d.ts",
"import": "./build/js/public/*.mjs",
"require": "./build/js/public/*.cjs"
}
Expand Down Expand Up @@ -53,6 +53,6 @@
],
"main": "./build/js/index.cjs",
"module": "./build/js/index.mjs",
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"type": "module"
}
5 changes: 2 additions & 3 deletions examples-extra/basic/sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "../../../monorepo/tsconfig/tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "src",
"outDir": "build/types",
"composite": true
},
"include": [
"./src/**/*",
".eslintrc.cjs",
"package.json"
".eslintrc.cjs"
],
"references": [
{
Expand Down
6 changes: 3 additions & 3 deletions examples-extra/one_dot_one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"exports": {
".": {
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"import": "./build/js/index.mjs",
"require": "./build/js/index.cjs"
},
"./*": {
"types": "./build/types/src/public/*.d.ts",
"types": "./build/types/public/*.d.ts",
"import": "./build/js/public/*.mjs",
"require": "./build/js/public/*.cjs"
}
Expand Down Expand Up @@ -56,5 +56,5 @@
],
"main": "./build/js/index.cjs",
"module": "./build/js/index.mjs",
"types": "./build/types/src/index.d.ts"
"types": "./build/types/index.d.ts"
}
5 changes: 2 additions & 3 deletions examples-extra/one_dot_one/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "../../monorepo/tsconfig/tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "src",
"outDir": "build/types",
"composite": true
},
"include": [
"./src/**/*",
".eslintrc.cjs",
"package.json"
".eslintrc.cjs"
],
"references": []
}
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"exports": {
".": {
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"import": "./build/js/index.mjs",
"require": "./build/js/index.js"
},
"./*": {
"types": "./build/types/src/public/*.d.ts",
"types": "./build/types/public/*.d.ts",
"import": "./build/js/public/*.mjs",
"require": "./build/js/public/*.js"
}
Expand Down Expand Up @@ -57,5 +57,5 @@
],
"main": "./build/js/index.js",
"module": "./build/js/index.mjs",
"types": "./build/types/src/index.d.ts"
"types": "./build/types/index.d.ts"
}
5 changes: 2 additions & 3 deletions packages/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "../../monorepo/tsconfig/tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "src",
"outDir": "build/types",
"composite": true
},
"include": [
"./src/**/*",
".eslintrc.cjs",
"package.json"
".eslintrc.cjs"
],
"references": [
{
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"exports": {
".": {
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"import": "./build/js/index.mjs",
"require": "./build/js/index.cjs"
},
"./*": {
"types": "./build/types/src/public/*.d.ts",
"types": "./build/types/public/*.d.ts",
"import": "./build/js/public/*.mjs",
"require": "./build/js/public/*.cjs"
}
Expand Down Expand Up @@ -77,6 +77,6 @@
],
"main": "./build/js/index.cjs",
"module": "./build/js/index.mjs",
"types": "./build/types/src/index.d.ts",
"types": "./build/types/index.d.ts",
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ function getTsCompilerOptions(packageType: "commonjs" | "module") {
return compilerOptions;
}

// eslint-disable-next-line @typescript-eslint/consistent-type-imports
type OurPackageJsonShape = typeof import("../../../../package.json");

async function getPackageJsonContents(
/** @internal */
export async function getPackageJsonContents(
name: string,
version: string,
sdkVersion: 1 | 2,
Expand All @@ -242,7 +240,7 @@ async function getPackageJsonContents(

const ourPackageJson = JSON.parse(
await fs.promises.readFile(ourPackageJsonPath, "utf-8"),
) as OurPackageJsonShape;
);

const esmPrefix = "./dist/module";
const commonjsPrefix = "./dist/commonjs";
Expand Down
122 changes: 122 additions & 0 deletions packages/cli/src/commands/typescript/generate/handleGenerate.test.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* 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 { afterEach, beforeEach, describe, expect, test } from "vitest";
import { getPackageJsonContents } from "./handleGenerate.mjs";

describe("handleGenerate", () => {
beforeEach(() => {
process.env.PACKAGE_API_VERSION = "99.9.9";
process.env.PACKAGE_CLIENT_VERSION = "88.8.8";
process.env.PACKAGE_LEGACY_CLIENT_VERSION = "77.7.7";
});

afterEach(() => {
delete process.env.PACKAGE_API_VERSION;
delete process.env.PACKAGE_CLIENT_VERSION;
delete process.env.PACKAGE_LEGACY_CLIENT_VERSION;
});

describe(getPackageJsonContents, () => {
describe("v1", () => {
test("returns the package.json contents", async () => {
expect(await getPackageJsonContents("foo", "1.1.1", 1))
.toMatchInlineSnapshot(`
{
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.2",
"@osdk/api": "^99.9.9",
"@osdk/legacy-client": "^77.7.7",
"tslib": "^2.6.2",
"typescript": "^5.4.2",
},
"exports": {
".": {
"import": "./dist/module/index.js",
"require": "./dist/commonjs/index.js",
},
"./ontology/objects": {
"import": "./dist/module/ontology/objects/index.js",
"require": "./dist/commonjs/ontology/objects/index.js",
},
},
"files": [
"**/*.js",
"**/*.d.ts",
"dist/**/package.json",
],
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"name": "foo",
"peerDependencies": {
"@osdk/api": "^99.9.9",
"@osdk/legacy-client": "^77.7.7",
},
"scripts": {
"check": "npm exec attw $(npm pack)",
"prepack": "tsc -p ./dist/module/tsconfig.json && tsc -p ./dist/commonjs/tsconfig.json",
},
"version": "1.1.1",
}
`);
});
});

describe("v2", () => {
test("returns the package.json contents", async () => {
expect(await getPackageJsonContents("foo", "1.2.3", 2))
.toMatchInlineSnapshot(`
{
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.2",
"@osdk/api": "^99.9.9",
"@osdk/client": "^88.8.8",
"tslib": "^2.6.2",
"typescript": "^5.4.2",
},
"exports": {
".": {
"import": "./dist/module/index.js",
"require": "./dist/commonjs/index.js",
},
"./ontology/objects": {
"import": "./dist/module/ontology/objects.js",
"require": "./dist/commonjs/ontology/objects.js",
},
},
"files": [
"**/*.js",
"**/*.d.ts",
"dist/**/package.json",
],
"main": "./dist/commonjs/index.js",
"module": "./dist/module/index.js",
"name": "foo",
"peerDependencies": {
"@osdk/api": "^99.9.9",
"@osdk/client": "^88.8.8",
},
"scripts": {
"check": "npm exec attw $(npm pack)",
"prepack": "tsc -p ./dist/module/tsconfig.json && tsc -p ./dist/commonjs/tsconfig.json",
},
"version": "1.2.3",
}
`);
});
});
});
});
5 changes: 2 additions & 3 deletions packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "../../monorepo/tsconfig/tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "src",
"outDir": "build/types",
"composite": true
},
"include": [
"./src/**/*",
".eslintrc.cjs",
"package.json"
".eslintrc.cjs"
],
"references": [
{
Expand Down
Loading

0 comments on commit 8da7dd8

Please sign in to comment.