diff --git a/.swcrc b/.swcrc index e8da5ffc6..a623edcfb 100644 --- a/.swcrc +++ b/.swcrc @@ -6,7 +6,10 @@ "tsx": false, "dynamicImport": true }, - "target": "es2020" + "target": "es2020", + "experimental": { + "emitIsolatedDts": true + } }, "module": { "type": "commonjs", diff --git a/change/change-4d116d1c-68e7-4744-ac24-707e35ddd69f.json b/change/change-4d116d1c-68e7-4744-ac24-707e35ddd69f.json new file mode 100644 index 000000000..fc386eff2 --- /dev/null +++ b/change/change-4d116d1c-68e7-4744-ac24-707e35ddd69f.json @@ -0,0 +1,18 @@ +{ + "changes": [ + { + "type": "patch", + "comment": "isolated declarations", + "packageName": "@lage-run/cache-github-actions", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "isolated declarations", + "packageName": "@lage-run/scheduler-types", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + } + ] +} \ No newline at end of file diff --git a/change/change-7f40e1b3-256a-42a3-a306-4cc681250ece.json b/change/change-7f40e1b3-256a-42a3-a306-4cc681250ece.json new file mode 100644 index 000000000..260b94e35 --- /dev/null +++ b/change/change-7f40e1b3-256a-42a3-a306-4cc681250ece.json @@ -0,0 +1,95 @@ +{ + "changes": [ + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/cache", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/cli", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/config", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/format-hrtime", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/globby", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/hasher", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/logger", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/reporters", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/rpc", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/runners", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/scheduler", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/target-graph", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + }, + { + "type": "patch", + "comment": "Adding isolated-declarations flag everywhere", + "packageName": "@lage-run/worker-threads-pool", + "email": "kchau@microsoft.com", + "dependentChangeType": "patch" + } + ] +} \ No newline at end of file diff --git a/lage.config.js b/lage.config.js index 6712655b9..7bd74aacc 100644 --- a/lage.config.js +++ b/lage.config.js @@ -7,12 +7,9 @@ module.exports = { pipeline: { "lage#bundle": ["^^transpile", "types"], types: { - type: "worker", - options: { - worker: path.join(__dirname, "scripts/worker/types.js"), - }, - dependsOn: ["^types"], - outputs: ["lib/**/*.d.ts"], + type: "npmScript", + dependsOn: ["^^transpile"], + outputs: [], }, isolatedTypes: { type: "worker", @@ -27,7 +24,7 @@ module.exports = { options: { worker: path.join(__dirname, "scripts/worker/transpile.js"), }, - outputs: ["lib/**/*.js"], + outputs: ["lib/**/*.js", "lib/**/*.map", "lib/**/*.d.ts"], }, test: { type: "worker", diff --git a/package.json b/package.json index 3ce0c111d..eead1f887 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "scripts": { "build": "lage transpile types build bundle", - "watch": "lage transpile isolatedTypes --no-cache --verbose --unstable-watch", + "watch": "lage transpile types --no-cache --verbose --unstable-watch", "change": "beachball change", "checkchange": "beachball check", "ci": "lage transpile types build test lint bundle", diff --git a/packages/cache-github-actions/package.json b/packages/cache-github-actions/package.json index 731356a96..22c5dd6f2 100644 --- a/packages/cache-github-actions/package.json +++ b/packages/cache-github-actions/package.json @@ -13,7 +13,8 @@ "scripts": { "build": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", - "lint": "monorepo-scripts lint" + "lint": "monorepo-scripts lint", + "types": "monorepo-scripts tsc" }, "dependencies": { "@actions/cache": "3.3.0", diff --git a/packages/cache/package.json b/packages/cache/package.json index 01493dbd5..6f2283a8f 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -14,7 +14,8 @@ "build": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", - "lint": "monorepo-scripts lint" + "lint": "monorepo-scripts lint", + "types": "monorepo-scripts tsc" }, "dependencies": { "@azure/core-auth": "1.10.1", diff --git a/packages/cache/src/backfillWrapper.ts b/packages/cache/src/backfillWrapper.ts index ee8c5f44d..668e5ec80 100644 --- a/packages/cache/src/backfillWrapper.ts +++ b/packages/cache/src/backfillWrapper.ts @@ -3,7 +3,7 @@ */ import * as os from "os"; -import { type Config, createDefaultConfig, getEnvConfig } from "backfill-config"; +import { createDefaultConfig, getEnvConfig } from "backfill-config"; import { makeLogger } from "backfill-logger"; import type { Logger as BackfillLogger } from "backfill-logger"; import type { CacheOptions } from "@lage-run/config"; @@ -32,15 +32,15 @@ export function createBackfillCacheConfig( cwd: string, cacheOptions: Partial | undefined = {}, backfillLogger: BackfillLogger -): Config { +): CacheOptions { const envConfig = getEnvConfig(backfillLogger); const mergedConfig = { ...createDefaultConfig(cwd), ...cacheOptions, ...envConfig, - } as Config; + } as CacheOptions; - if (mergedConfig.cacheStorageConfig.provider === "azure-blob") { + if (mergedConfig.cacheStorageConfig?.provider === "azure-blob") { const azureOptions = mergedConfig.cacheStorageConfig.options; if ("connectionString" in azureOptions && !isTokenConnectionString(azureOptions.connectionString)) { /** Pass through optional credentialName from config to select a specific credential implementation diff --git a/packages/cli/package.json b/packages/cli/package.json index ebf0dc73c..3ea09945b 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -15,8 +15,9 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, diff --git a/packages/config/package.json b/packages/config/package.json index a8e83fe72..45dee4614 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -11,9 +11,10 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", - "test": "jest", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "dependencies": { diff --git a/packages/e2e-tests/package.json b/packages/e2e-tests/package.json index a1af3d7d5..55edfc9d4 100644 --- a/packages/e2e-tests/package.json +++ b/packages/e2e-tests/package.json @@ -10,8 +10,9 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, diff --git a/packages/format-hrtime/package.json b/packages/format-hrtime/package.json index 7bff0a553..508b3a88d 100644 --- a/packages/format-hrtime/package.json +++ b/packages/format-hrtime/package.json @@ -9,9 +9,10 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", - "test": "jest", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "devDependencies": { diff --git a/packages/globby/tsconfig.json b/packages/globby/tsconfig.json index a5ed253bf..07dea7451 100644 --- a/packages/globby/tsconfig.json +++ b/packages/globby/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../tsconfig.lage2.json", "compilerOptions": { "outDir": "./lib", - "emitDeclarationOnly": true, "module": "Node16", "moduleResolution": "Node16", "lib": ["ES2020"] diff --git a/packages/hasher/package.json b/packages/hasher/package.json index d57f1d340..a271a4d2e 100644 --- a/packages/hasher/package.json +++ b/packages/hasher/package.json @@ -9,8 +9,9 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, diff --git a/packages/logger/package.json b/packages/logger/package.json index d1f66babd..6db8db45f 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -11,9 +11,10 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", - "test": "jest", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "devDependencies": { diff --git a/packages/monorepo-fixture/package.json b/packages/monorepo-fixture/package.json index fa2cd2994..fbc1e322c 100644 --- a/packages/monorepo-fixture/package.json +++ b/packages/monorepo-fixture/package.json @@ -10,8 +10,10 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "devDependencies": { diff --git a/packages/reporters/package.json b/packages/reporters/package.json index da30513f2..d58aa6554 100644 --- a/packages/reporters/package.json +++ b/packages/reporters/package.json @@ -11,9 +11,10 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", - "test": "jest", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "dependencies": { diff --git a/packages/rpc/package.json b/packages/rpc/package.json index 7272f6b1b..8d37cb93f 100644 --- a/packages/rpc/package.json +++ b/packages/rpc/package.json @@ -13,7 +13,8 @@ "scripts": { "lint": "buf lint", "generate": "buf generate", - "build": "tsc" + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc" }, "dependencies": { "@bufbuild/protobuf": "^1.10.0", @@ -25,7 +26,8 @@ "devDependencies": { "@bufbuild/buf": "^1.39.0", "@bufbuild/protoc-gen-es": "^1.10.0", - "@connectrpc/protoc-gen-connect-es": "^1.4.0" + "@connectrpc/protoc-gen-connect-es": "^1.4.0", + "@lage-run/monorepo-scripts": "workspace:^" }, "publishConfig": { "access": "public" diff --git a/packages/runners/package.json b/packages/runners/package.json index 2ad8bd1e8..d8fc33c11 100644 --- a/packages/runners/package.json +++ b/packages/runners/package.json @@ -12,6 +12,7 @@ "types": "lib/index.d.ts", "scripts": { "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" diff --git a/packages/scheduler-types/package.json b/packages/scheduler-types/package.json index 4e09d38a7..f1e735cdd 100644 --- a/packages/scheduler-types/package.json +++ b/packages/scheduler-types/package.json @@ -12,7 +12,9 @@ "types": "lib/index.d.ts", "scripts": { "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", + "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, "dependencies": { diff --git a/packages/scheduler/package.json b/packages/scheduler/package.json index e8880cae9..4d95552bf 100644 --- a/packages/scheduler/package.json +++ b/packages/scheduler/package.json @@ -12,6 +12,7 @@ "types": "lib/index.d.ts", "scripts": { "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" diff --git a/packages/target-graph/package.json b/packages/target-graph/package.json index 3c7d948f8..8b69daefa 100644 --- a/packages/target-graph/package.json +++ b/packages/target-graph/package.json @@ -11,8 +11,9 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "tsc", - "start": "tsc -w --preserveWatchOutput", + "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", + "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" }, diff --git a/packages/worker-threads-pool/package.json b/packages/worker-threads-pool/package.json index 31b935d25..fb5f3e5a9 100644 --- a/packages/worker-threads-pool/package.json +++ b/packages/worker-threads-pool/package.json @@ -12,6 +12,7 @@ "types": "lib/index.d.ts", "scripts": { "build": "monorepo-scripts tsc", + "types": "monorepo-scripts tsc", "start": "monorepo-scripts tsc -w --preserveWatchOutput", "test": "monorepo-scripts jest", "lint": "monorepo-scripts lint" diff --git a/scripts/config/tsconfig.base.json b/scripts/config/tsconfig.base.json index da4796630..694cd99a3 100644 --- a/scripts/config/tsconfig.base.json +++ b/scripts/config/tsconfig.base.json @@ -5,8 +5,8 @@ "moduleResolution": "Node", "declaration": true, "isolatedModules": true, + "isolatedDeclarations": true, "lib": ["ES2020"], - "allowJs": true, "strict": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, diff --git a/scripts/worker/transpile.js b/scripts/worker/transpile.js index 363329b2f..f0ecd6291 100644 --- a/scripts/worker/transpile.js +++ b/scripts/worker/transpile.js @@ -1,12 +1,10 @@ // @ts-check const path = require("path"); -const fs = require("fs"); const fsPromises = require("fs/promises"); const swc = require("@swc/core"); const { findProjectRoot } = require("workspace-tools"); const root = findProjectRoot(process.cwd()) ?? process.cwd(); -const swcOptions = JSON.parse(fs.readFileSync(path.join(root, ".swcrc"), "utf8")); module.exports = async function transpile(data) { const { target } = data; @@ -37,7 +35,7 @@ module.exports = async function transpile(data) { .replace(".ts", ".js"); const dest = path.join(target.cwd, targetRelativePath); const swcOutput = await swc.transformFile(fullPath, { - ...swcOptions, + configFile: path.join(root, ".swcrc"), sourceFileName: path.relative(path.dirname(dest), fullPath).replace(/\\/g, "/"), }); @@ -48,6 +46,15 @@ module.exports = async function transpile(data) { if (swcOutput.map) { await fsPromises.writeFile(destMap, swcOutput.map); } + + // @ts-expect-error + if (swcOutput.output) { + // @ts-expect-error + const output = JSON.parse(swcOutput.output); + const decls = dest.replace(/\.js$/, ".d.ts"); + // @ts-ignore + await fsPromises.writeFile(decls, output.__swc_isolated_declarations__); + } } } } diff --git a/scripts/worker/types.js b/scripts/worker/types.js deleted file mode 100644 index 446a98954..000000000 --- a/scripts/worker/types.js +++ /dev/null @@ -1,102 +0,0 @@ -// @ts-check -const ts = require("typescript"); -const path = require("path"); -const { existsSync } = require("fs"); - -let oldProgram; - -const log = (msg) => { - process.stdout.write(msg + "\n"); -}; - -/** - * Worker Run() function - * @param {*} data Lage Context - */ -async function run(data) { - const { target } = data; // Lage target data - - const tsconfigFile = "tsconfig.json"; - const tsconfigJsonFile = path.join(target.cwd, tsconfigFile); - - // Find tsconfig.json - if (!existsSync(tsconfigJsonFile)) { - log("no tsconfig.json found - skipping this package"); - // pass - return; - } - - // Parse tsconfig - log(`Parsing Config...`); - const configParserHost = parseConfigHostFromCompilerHostLike(ts.sys); - const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(tsconfigJsonFile, {}, configParserHost); - if (!parsedCommandLine) { - throw new Error("Could not parse tsconfig.json"); - } - - // for "types," we only generate declaration files - parsedCommandLine.options.emitDeclarationOnly = true; - - const compilerOptions = parsedCommandLine.options; - - // Creating compilation host program - log(`Creating Host Compiler...`); - const compilerHost = ts.createCompilerHost(compilerOptions); - - const program = ts.createProgram(parsedCommandLine.fileNames, compilerOptions, compilerHost, oldProgram); - oldProgram = program; - - const errors = { - semantics: program.getSemanticDiagnostics(), - declaration: program.getDeclarationDiagnostics(), - syntactic: program.getSyntacticDiagnostics(), - global: program.getGlobalDiagnostics(), - }; - - const allErrors = []; - - log(`Compiling...`); - try { - program.emit(); - } catch (e) { - log(`Encountered Error while transpiling: ${e.messageText}`); - throw new Error("Encountered Error while transpiling"); - } - let hasErrors = false; - - for (const kind of Object.keys(errors)) { - for (const diagnostics of errors[kind]) { - hasErrors = true; - allErrors.push(diagnostics); - } - } - - if (hasErrors) { - log(`Type errors found in ${target.packageName}`); - log(ts.formatDiagnosticsWithColorAndContext(allErrors, compilerHost)); - - throw new Error("Failed to compile"); - } else { - log("Compiled successfully"); - - return; - } -} - -function parseConfigHostFromCompilerHostLike(host) { - return { - fileExists: (f) => host.fileExists(f), - readDirectory(root, extensions, excludes, includes, depth) { - return host.readDirectory(root, extensions, excludes, includes, depth); - }, - readFile: (f) => host.readFile(f), - useCaseSensitiveFileNames: host.useCaseSensitiveFileNames, - getCurrentDirectory: host.getCurrentDirectory, - onUnRecoverableConfigFileDiagnostic: (d) => { - throw new Error(ts.flattenDiagnosticMessageText(d.messageText, "")); - }, - trace: host.trace, - }; -} - -module.exports = run; diff --git a/yarn.lock b/yarn.lock index 26ff67b37..dd308738b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1766,6 +1766,7 @@ __metadata: "@connectrpc/connect-fastify": "npm:^1.4.0" "@connectrpc/connect-node": "npm:^1.4.0" "@connectrpc/protoc-gen-connect-es": "npm:^1.4.0" + "@lage-run/monorepo-scripts": "workspace:^" fastify: "npm:^4.28.1" languageName: unknown linkType: soft