Skip to content

Commit d70cc8a

Browse files
committed
Add pnp tests
1 parent c677ab5 commit d70cc8a

18 files changed

+1551
-0
lines changed

internal/testutil/harnessutil/harnessutil.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/microsoft/typescript-go/internal/core"
2424
"github.com/microsoft/typescript-go/internal/outputpaths"
2525
"github.com/microsoft/typescript-go/internal/parser"
26+
"github.com/microsoft/typescript-go/internal/pnp"
2627
"github.com/microsoft/typescript-go/internal/repo"
2728
"github.com/microsoft/typescript-go/internal/sourcemap"
2829
"github.com/microsoft/typescript-go/internal/testutil"
@@ -208,6 +209,11 @@ func CompileFilesEx(
208209
fs = bundled.WrapFS(fs)
209210
fs = NewOutputRecorderFS(fs)
210211

212+
manifestData, _ := fs.ReadFile("/.pnp.data.json")
213+
// Instantiate a unique PnP API per goroutine, or disable PnP if no manifestData found
214+
pnp.OverridePnpApi(fs, manifestData)
215+
defer pnp.ClearTestPnpCache()
216+
211217
host := createCompilerHost(fs, bundled.LibPath(), currentDirectory)
212218
var configFile *tsoptions.TsConfigSourceFile
213219
var errors []*ast.Diagnostic
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//// [tests/cases/compiler/pnpDeclarationEmitWorkspace.ts] ////
2+
3+
//// [.pnp.cjs]
4+
module.exports = {};
5+
6+
//// [.pnp.data.json]
7+
{
8+
"dependencyTreeRoots": [
9+
{
10+
"name": "project",
11+
"reference": "workspace:."
12+
}
13+
],
14+
"ignorePatternData": null,
15+
"enableTopLevelFallback": false,
16+
"fallbackPool": [],
17+
"fallbackExclusionList": [],
18+
"packageRegistryData": [
19+
["project", [
20+
["workspace:.", {
21+
"packageLocation": "./",
22+
"packageDependencies": [
23+
["package-a", "workspace:packages/package-a"]
24+
]
25+
}]
26+
]],
27+
["package-a", [
28+
["workspace:packages/package-a", {
29+
"packageLocation": "./packages/package-a/",
30+
"packageDependencies": []
31+
}]
32+
]]
33+
]
34+
}
35+
36+
//// [package.json]
37+
{
38+
"name": "project",
39+
"workspaces": [
40+
"packages/*"
41+
],
42+
"dependencies": {
43+
"package-a": "workspace:*"
44+
}
45+
}
46+
47+
//// [package.json]
48+
{
49+
"name": "package-a",
50+
"exports": {
51+
"./other-subpath": {
52+
"types": "./index.d.ts",
53+
"default": "./index.ts"
54+
}
55+
},
56+
"dependencies": {
57+
"package-b": "workspace:*"
58+
}
59+
}
60+
61+
//// [index.d.ts]
62+
export interface BaseConfig {
63+
timeout: number;
64+
retries: number;
65+
}
66+
67+
export interface DataOptions {
68+
format: "json" | "xml";
69+
encoding: string;
70+
}
71+
72+
export interface ServiceConfig extends BaseConfig {
73+
endpoint: string;
74+
options: DataOptions;
75+
}
76+
77+
export type ConfigFactory = (endpoint: string) => ServiceConfig;
78+
79+
export declare function createServiceConfig(endpoint: string): ServiceConfig;
80+
81+
//// [index.ts]
82+
import type { ServiceConfig, ConfigFactory } from 'package-a/other-subpath';
83+
import { createServiceConfig } from 'package-a/other-subpath';
84+
85+
export function initializeService(url: string): ServiceConfig {
86+
return createServiceConfig(url);
87+
}
88+
89+
export const factory = createServiceConfig;
90+
91+
export interface AppConfig {
92+
service: ServiceConfig;
93+
debug: boolean;
94+
}
95+
96+
97+
//// [index.js]
98+
"use strict";
99+
Object.defineProperty(exports, "__esModule", { value: true });
100+
exports.factory = void 0;
101+
exports.initializeService = initializeService;
102+
const other_subpath_1 = require("package-a/other-subpath");
103+
function initializeService(url) {
104+
return (0, other_subpath_1.createServiceConfig)(url);
105+
}
106+
exports.factory = other_subpath_1.createServiceConfig;
107+
108+
109+
//// [index.d.ts]
110+
import type { ServiceConfig } from 'package-a/other-subpath';
111+
import { createServiceConfig } from 'package-a/other-subpath';
112+
export declare function initializeService(url: string): ServiceConfig;
113+
export declare const factory: typeof createServiceConfig;
114+
export interface AppConfig {
115+
service: ServiceConfig;
116+
debug: boolean;
117+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//// [tests/cases/compiler/pnpDeclarationEmitWorkspace.ts] ////
2+
3+
=== /src/index.ts ===
4+
import type { ServiceConfig, ConfigFactory } from 'package-a/other-subpath';
5+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.ts, 0, 13))
6+
>ConfigFactory : Symbol(ConfigFactory, Decl(index.ts, 0, 28))
7+
8+
import { createServiceConfig } from 'package-a/other-subpath';
9+
>createServiceConfig : Symbol(createServiceConfig, Decl(index.ts, 1, 8))
10+
11+
export function initializeService(url: string): ServiceConfig {
12+
>initializeService : Symbol(initializeService, Decl(index.ts, 1, 62))
13+
>url : Symbol(url, Decl(index.ts, 3, 34))
14+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.ts, 0, 13))
15+
16+
return createServiceConfig(url);
17+
>createServiceConfig : Symbol(createServiceConfig, Decl(index.ts, 1, 8))
18+
>url : Symbol(url, Decl(index.ts, 3, 34))
19+
}
20+
21+
export const factory = createServiceConfig;
22+
>factory : Symbol(factory, Decl(index.ts, 7, 12))
23+
>createServiceConfig : Symbol(createServiceConfig, Decl(index.ts, 1, 8))
24+
25+
export interface AppConfig {
26+
>AppConfig : Symbol(AppConfig, Decl(index.ts, 7, 43))
27+
28+
service: ServiceConfig;
29+
>service : Symbol(AppConfig.service, Decl(index.ts, 9, 28))
30+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.ts, 0, 13))
31+
32+
debug: boolean;
33+
>debug : Symbol(AppConfig.debug, Decl(index.ts, 10, 25))
34+
}
35+
36+
=== /packages/package-a/index.d.ts ===
37+
export interface BaseConfig {
38+
>BaseConfig : Symbol(BaseConfig, Decl(index.d.ts, 0, 0))
39+
40+
timeout: number;
41+
>timeout : Symbol(BaseConfig.timeout, Decl(index.d.ts, 0, 29))
42+
43+
retries: number;
44+
>retries : Symbol(BaseConfig.retries, Decl(index.d.ts, 1, 18))
45+
}
46+
47+
export interface DataOptions {
48+
>DataOptions : Symbol(DataOptions, Decl(index.d.ts, 3, 1))
49+
50+
format: "json" | "xml";
51+
>format : Symbol(DataOptions.format, Decl(index.d.ts, 5, 30))
52+
53+
encoding: string;
54+
>encoding : Symbol(DataOptions.encoding, Decl(index.d.ts, 6, 25))
55+
}
56+
57+
export interface ServiceConfig extends BaseConfig {
58+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.d.ts, 8, 1))
59+
>BaseConfig : Symbol(BaseConfig, Decl(index.d.ts, 0, 0))
60+
61+
endpoint: string;
62+
>endpoint : Symbol(ServiceConfig.endpoint, Decl(index.d.ts, 10, 51))
63+
64+
options: DataOptions;
65+
>options : Symbol(ServiceConfig.options, Decl(index.d.ts, 11, 19))
66+
>DataOptions : Symbol(DataOptions, Decl(index.d.ts, 3, 1))
67+
}
68+
69+
export type ConfigFactory = (endpoint: string) => ServiceConfig;
70+
>ConfigFactory : Symbol(ConfigFactory, Decl(index.d.ts, 13, 1))
71+
>endpoint : Symbol(endpoint, Decl(index.d.ts, 15, 29))
72+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.d.ts, 8, 1))
73+
74+
export declare function createServiceConfig(endpoint: string): ServiceConfig;
75+
>createServiceConfig : Symbol(createServiceConfig, Decl(index.d.ts, 15, 64))
76+
>endpoint : Symbol(endpoint, Decl(index.d.ts, 17, 44))
77+
>ServiceConfig : Symbol(ServiceConfig, Decl(index.d.ts, 8, 1))
78+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//// [tests/cases/compiler/pnpDeclarationEmitWorkspace.ts] ////
2+
3+
=== /src/index.ts ===
4+
import type { ServiceConfig, ConfigFactory } from 'package-a/other-subpath';
5+
>ServiceConfig : ServiceConfig
6+
>ConfigFactory : ConfigFactory
7+
8+
import { createServiceConfig } from 'package-a/other-subpath';
9+
>createServiceConfig : (endpoint: string) => ServiceConfig
10+
11+
export function initializeService(url: string): ServiceConfig {
12+
>initializeService : (url: string) => ServiceConfig
13+
>url : string
14+
15+
return createServiceConfig(url);
16+
>createServiceConfig(url) : ServiceConfig
17+
>createServiceConfig : (endpoint: string) => ServiceConfig
18+
>url : string
19+
}
20+
21+
export const factory = createServiceConfig;
22+
>factory : (endpoint: string) => ServiceConfig
23+
>createServiceConfig : (endpoint: string) => ServiceConfig
24+
25+
export interface AppConfig {
26+
service: ServiceConfig;
27+
>service : ServiceConfig
28+
29+
debug: boolean;
30+
>debug : boolean
31+
}
32+
33+
=== /packages/package-a/index.d.ts ===
34+
export interface BaseConfig {
35+
timeout: number;
36+
>timeout : number
37+
38+
retries: number;
39+
>retries : number
40+
}
41+
42+
export interface DataOptions {
43+
format: "json" | "xml";
44+
>format : "json" | "xml"
45+
46+
encoding: string;
47+
>encoding : string
48+
}
49+
50+
export interface ServiceConfig extends BaseConfig {
51+
endpoint: string;
52+
>endpoint : string
53+
54+
options: DataOptions;
55+
>options : DataOptions
56+
}
57+
58+
export type ConfigFactory = (endpoint: string) => ServiceConfig;
59+
>ConfigFactory : ConfigFactory
60+
>endpoint : string
61+
62+
export declare function createServiceConfig(endpoint: string): ServiceConfig;
63+
>createServiceConfig : (endpoint: string) => ServiceConfig
64+
>endpoint : string
65+
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//// [tests/cases/compiler/pnpSimpleTest.ts] ////
2+
3+
//// [.pnp.cjs]
4+
module.exports = {};
5+
6+
//// [.pnp.data.json]
7+
{
8+
"dependencyTreeRoots": [
9+
{
10+
"name": "project",
11+
"reference": "workspace:."
12+
}
13+
],
14+
"ignorePatternData": null,
15+
"enableTopLevelFallback": false,
16+
"fallbackPool": [],
17+
"fallbackExclusionList": [],
18+
"packageRegistryData": [
19+
["project", [
20+
["workspace:.", {
21+
"packageLocation": "./",
22+
"packageDependencies": [
23+
["package-a", "npm:1.0.0"],
24+
["package-b", "npm:2.0.0"]
25+
]
26+
}]
27+
]],
28+
["package-a", [
29+
["npm:1.0.0", {
30+
"packageLocation": "./.yarn/cache/package-a-npm-1.0.0-abcd1234/node_modules/package-a/",
31+
"packageDependencies": []
32+
}]
33+
]],
34+
["package-b", [
35+
["npm:2.0.0", {
36+
"packageLocation": "./.yarn/cache/package-b-npm-2.0.0-efgh5678/node_modules/package-b/",
37+
"packageDependencies": []
38+
}]
39+
]]
40+
]
41+
}
42+
43+
//// [package.json]
44+
{
45+
"name": "project",
46+
"dependencies": {
47+
"package-a": "npm:1.0.0",
48+
"package-b": "npm:2.0.0"
49+
}
50+
}
51+
52+
//// [package.json]
53+
{
54+
"name": "package-a",
55+
"version": "1.0.0",
56+
"exports": {
57+
".": "./index.js"
58+
},
59+
"types": "index.d.ts"
60+
}
61+
62+
//// [index.js]
63+
exports.helperA = function(value) {
64+
return "Helper A: " + value;
65+
};
66+
67+
//// [index.d.ts]
68+
export declare function helperA(value: string): string;
69+
70+
//// [package.json]
71+
{
72+
"name": "package-b",
73+
"version": "2.0.0",
74+
"exports": {
75+
".": "./index.js"
76+
},
77+
"types": "index.d.ts"
78+
}
79+
80+
//// [index.js]
81+
exports.helperB = function(value) {
82+
return "Helper B: " + value;
83+
};
84+
85+
//// [index.d.ts]
86+
export declare function helperB(value: number): string;
87+
88+
//// [index.ts]
89+
// Workspace package that imports both third-party dependencies
90+
import { helperA } from 'package-a';
91+
import { helperB } from 'package-b';
92+
93+
export function processData(text: string, num: number): string {
94+
const resultA = helperA(text);
95+
const resultB = helperB(num);
96+
return `${resultA} | ${resultB}`;
97+
}
98+
99+
//// [index.js]
100+
"use strict";
101+
Object.defineProperty(exports, "__esModule", { value: true });
102+
exports.processData = processData;
103+
// Workspace package that imports both third-party dependencies
104+
const package_a_1 = require("package-a");
105+
const package_b_1 = require("package-b");
106+
function processData(text, num) {
107+
const resultA = (0, package_a_1.helperA)(text);
108+
const resultB = (0, package_b_1.helperB)(num);
109+
return `${resultA} | ${resultB}`;
110+
}

0 commit comments

Comments
 (0)