From 0449dd92ce3297b065c171efafc28d1f877432cc Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Tue, 16 Nov 2021 08:16:47 +0000 Subject: [PATCH] revert: "fix: dependency submodules may not be discovered (#3151)" (#3170) This reverts commit 5768bb9951856f4a051c24db7f56d23fd8573815. The commit breaks the build of CDKv2 alpha modules. see https://github.com/aws/aws-cdk/pull/17502 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- lerna.json | 3 +- package.json | 1 - packages/jsii/lib/assembler.ts | 8 +--- packages/jsii/lib/compiler.ts | 41 +++---------------- .../@barrelimports/consumer/.gitignore | 4 -- .../@barrelimports/consumer/README.md | 6 --- .../@barrelimports/consumer/lib/index.ts | 6 --- .../@barrelimports/consumer/package.json | 30 -------------- .../@barrelimports/provider/.gitignore | 4 -- .../@barrelimports/provider/README.md | 5 --- .../@barrelimports/provider/lib/index.ts | 1 - .../@barrelimports/provider/lib/namespaced.ts | 3 -- .../@barrelimports/provider/package.json | 26 ------------ regression-tests/README.md | 10 ----- 14 files changed, 8 insertions(+), 140 deletions(-) delete mode 100644 regression-tests/@barrelimports/consumer/.gitignore delete mode 100644 regression-tests/@barrelimports/consumer/README.md delete mode 100644 regression-tests/@barrelimports/consumer/lib/index.ts delete mode 100644 regression-tests/@barrelimports/consumer/package.json delete mode 100644 regression-tests/@barrelimports/provider/.gitignore delete mode 100644 regression-tests/@barrelimports/provider/README.md delete mode 100644 regression-tests/@barrelimports/provider/lib/index.ts delete mode 100644 regression-tests/@barrelimports/provider/lib/namespaced.ts delete mode 100644 regression-tests/@barrelimports/provider/package.json delete mode 100644 regression-tests/README.md diff --git a/lerna.json b/lerna.json index 7feca2c485..197ff0284b 100644 --- a/lerna.json +++ b/lerna.json @@ -3,8 +3,7 @@ "npmClient": "yarn", "useWorkspaces": true, "packages": [ - "packages/*", - "regression-tests/@*/*" + "packages/*" ], "command": { "bootstrap": { diff --git a/package.json b/package.json index a663eca198..90690b0f36 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "packages/*", "packages/@jsii/*", "packages/@scope/*", - "regression-tests/@*/*", "tools/*" ], "nohoist": [ diff --git a/packages/jsii/lib/assembler.ts b/packages/jsii/lib/assembler.ts index c3c0de3c53..675653ad4e 100644 --- a/packages/jsii/lib/assembler.ts +++ b/packages/jsii/lib/assembler.ts @@ -3213,13 +3213,7 @@ function inferRootDir(program: ts.Program): string | undefined { .map((fileName) => path.relative(program.getCurrentDirectory(), path.dirname(fileName)), ) - .map(segmentPath) - // Dependency entry points are in this path, and they MAY resolve from the - // same mono-repo, in which case they won't appear to be external libraries, - // as there may not be a `/node_modules/` segment in their canonical path. - // They well however come from a parent directory, so their path segments - // will start with "..". - .filter(([head]) => head !== '..'); + .map(segmentPath); const maxPrefix = Math.min( ...directories.map((segments) => segments.length - 1), diff --git a/packages/jsii/lib/compiler.ts b/packages/jsii/lib/compiler.ts index 7f443f3ee9..aaae7f1799 100644 --- a/packages/jsii/lib/compiler.ts +++ b/packages/jsii/lib/compiler.ts @@ -133,15 +133,11 @@ export class Compiler implements Emitter { const pi = this.options.projectInfo; const projectRoot = pi.projectRoot; const host = ts.createWatchCompilerHost( - this.rootFiles, + this.configPath, { ...pi.tsc, ...BASE_COMPILER_OPTIONS, noEmitOnError: false, - tsBuildInfoFile: path.join( - pi.tsc?.outDir ?? pi.tsc?.rootDir ?? pi.projectRoot, - 'tsconfig.tsbuildinfo', - ), }, { ...ts.sys, @@ -152,7 +148,6 @@ export class Compiler implements Emitter { ts.createEmitAndSemanticDiagnosticsBuilderProgram, opts?.reportDiagnostics, opts?.reportWatchStatus, - this.typescriptConfig?.references, ); if (!host.getDefaultLibLocation) { throw new Error( @@ -500,47 +495,23 @@ export class Compiler implements Emitter { * This makes it so that running 'tsc' and running 'jsii' has the same behavior. */ private determineSources(files: string[]): string[] { - const ret = new Set(); + const ret = new Array(); if (files.length > 0) { - for (const file of files) { - ret.add(path.resolve(this.options.projectInfo.projectRoot, file)); - } + ret.push(...files); } else { const parseConfigHost = parseConfigHostFromCompilerHost( this.compilerHost, ); - // Note: the fileNames here are resolved by the parseConfigHost. - const { fileNames } = ts.parseJsonConfigFileContent( + const parsed = ts.parseJsonConfigFileContent( this.typescriptConfig, parseConfigHost, this.options.projectInfo.projectRoot, ); - for (const file of fileNames) { - ret.add(file); - } + ret.push(...parsed.fileNames); } - // Bonus: ensure all dependencies' entry points are included in the compiler - // input path. This guarantees we have symbols for all types, from the - // module root, which is necessary in order to properly detect submodules. - for (const assm of this.options.projectInfo.dependencyClosure) { - const { resolvedModule } = ts.resolveModuleName( - assm.name, - path.join( - this.options.projectInfo.projectRoot, - this.options.projectInfo.types, - ), - this.typescriptConfig?.compilerOptions ?? {}, - ts.sys, - ); - if (!resolvedModule) { - continue; - } - ret.add(resolvedModule.resolvedFileName); - } - - return Array.from(ret); + return ret; } /** diff --git a/regression-tests/@barrelimports/consumer/.gitignore b/regression-tests/@barrelimports/consumer/.gitignore deleted file mode 100644 index 0c4e0081d6..0000000000 --- a/regression-tests/@barrelimports/consumer/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.jsii -/tsconfig.json -*.js -*.d.ts diff --git a/regression-tests/@barrelimports/consumer/README.md b/regression-tests/@barrelimports/consumer/README.md deleted file mode 100644 index eaf22f65b1..0000000000 --- a/regression-tests/@barrelimports/consumer/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# @barrelimport/consumer - -This library re-exports a type imported from a barrel location within -`@barrelimport/provider`, without actually importing `@barrelimport/provider` -itself, so we validate the jsii compiler correctly identifies the submodule -declarations. diff --git a/regression-tests/@barrelimports/consumer/lib/index.ts b/regression-tests/@barrelimports/consumer/lib/index.ts deleted file mode 100644 index d5ced1d6bf..0000000000 --- a/regression-tests/@barrelimports/consumer/lib/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Directly importing NamespacedStruct, NEVER having imported @barrelimports/provider -import { NamespacedStruct } from '@barrelimports/provider/lib/namespaced'; - -export class UsingBarrelImport { - public constructor(public readonly props: NamespacedStruct) { } -} diff --git a/regression-tests/@barrelimports/consumer/package.json b/regression-tests/@barrelimports/consumer/package.json deleted file mode 100644 index 716fbdfd2d..0000000000 --- a/regression-tests/@barrelimports/consumer/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "@barrelimports/consumer", - "version": "0.0.0", - "private": true, - "license": "Apache-2.0", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com" - }, - "repository": { - "type": "git", - "url": "https://github.com/aws/jsii.git", - "directory": "regression-tests/@barrelimports/provider" - }, - "scripts": { - "build": "jsii" - }, - "peerDependencies": { - "@barrelimports/provider": "0.0.0" - }, - "devDependencies": { - "@barrelimports/provider": "0.0.0", - "jsii": "^0.0.0" - }, - "jsii": { - "targets": {} - } -} diff --git a/regression-tests/@barrelimports/provider/.gitignore b/regression-tests/@barrelimports/provider/.gitignore deleted file mode 100644 index 0c4e0081d6..0000000000 --- a/regression-tests/@barrelimports/provider/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/.jsii -/tsconfig.json -*.js -*.d.ts diff --git a/regression-tests/@barrelimports/provider/README.md b/regression-tests/@barrelimports/provider/README.md deleted file mode 100644 index 32226a5f72..0000000000 --- a/regression-tests/@barrelimports/provider/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @barrelimport/provider - -This library provides a single namespaced export struct, so that we can validate -the jsii compiler is correctly able to identify submodule declarations when the -package entry point is never imported by the consuming code. diff --git a/regression-tests/@barrelimports/provider/lib/index.ts b/regression-tests/@barrelimports/provider/lib/index.ts deleted file mode 100644 index be34190b86..0000000000 --- a/regression-tests/@barrelimports/provider/lib/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as namespaced from './namespaced'; diff --git a/regression-tests/@barrelimports/provider/lib/namespaced.ts b/regression-tests/@barrelimports/provider/lib/namespaced.ts deleted file mode 100644 index b64a2a52d0..0000000000 --- a/regression-tests/@barrelimports/provider/lib/namespaced.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface NamespacedStruct { - readonly name: string; -} diff --git a/regression-tests/@barrelimports/provider/package.json b/regression-tests/@barrelimports/provider/package.json deleted file mode 100644 index 58733bc50a..0000000000 --- a/regression-tests/@barrelimports/provider/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@barrelimports/provider", - "version": "0.0.0", - "private": true, - "license": "Apache-2.0", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "author": { - "name": "Amazon Web Services", - "url": "https://aws.amazon.com" - }, - "repository": { - "type": "git", - "url": "https://github.com/aws/jsii.git", - "directory": "regression-tests/@barrelimports/provider" - }, - "scripts": { - "build": "jsii" - }, - "devDependencies": { - "jsii": "^0.0.0" - }, - "jsii": { - "targets": {} - } -} diff --git a/regression-tests/README.md b/regression-tests/README.md deleted file mode 100644 index 8dd92a9763..0000000000 --- a/regression-tests/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Regression Tests - -This directory contains packages that are supposed to cleanly compile using -`jsii`. This validates the compiler is able to correctly interpret the source. - -When adding new tests, be sure to follow these guidelines: - -- Create a new namespace for each regression scenario -- All packages should have `private: true` in their `package.json` -- Provide a README.md with an explanation of what the package(s) validate