Skip to content

Commit 854be04

Browse files
committed
Add pnp tests
1 parent 86f5666 commit 854be04

19 files changed

+1561
-1
lines changed

internal/pnp/pnp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package pnp
22

3+
import "strings"
4+
35
func InitPnpApi(fs PnpApiFS, filePath string) *PnpApi {
46
pnpApi := &PnpApi{fs: fs, url: filePath}
57

@@ -11,3 +13,7 @@ func InitPnpApi(fs PnpApiFS, filePath string) *PnpApi {
1113

1214
return nil
1315
}
16+
17+
func IsPnpLoaderFile(path string) bool {
18+
return strings.HasSuffix(path, ".pnp.cjs")
19+
}

internal/testutil/tsbaseline/js_emit_baseline.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/microsoft/typescript-go/internal/collections"
1010
"github.com/microsoft/typescript-go/internal/core"
1111
"github.com/microsoft/typescript-go/internal/parser"
12+
"github.com/microsoft/typescript-go/internal/pnp"
1213
"github.com/microsoft/typescript-go/internal/testutil/baseline"
1314
"github.com/microsoft/typescript-go/internal/testutil/harnessutil"
1415
"github.com/microsoft/typescript-go/internal/tspath"
@@ -213,7 +214,7 @@ func prepareDeclarationCompilationContext(
213214
}
214215

215216
addDtsFile := func(file *harnessutil.TestFile, dtsFiles []*harnessutil.TestFile) []*harnessutil.TestFile {
216-
if tspath.IsDeclarationFileName(file.UnitName) || tspath.HasJSONFileExtension(file.UnitName) {
217+
if tspath.IsDeclarationFileName(file.UnitName) || tspath.HasJSONFileExtension(file.UnitName) || pnp.IsPnpLoaderFile(file.UnitName) {
217218
dtsFiles = append(dtsFiles, file)
218219
} else if tspath.HasTSFileExtension(file.UnitName) || (tspath.HasJSFileExtension(file.UnitName) && options.GetAllowJS()) {
219220
declFile := findResultCodeFile(file.UnitName)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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.js"
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.js]
82+
exports.initializeService = function(url) {};
83+
84+
85+
//// [index.ts]
86+
import type { ServiceConfig, ConfigFactory } from 'package-a/other-subpath';
87+
import { createServiceConfig } from 'package-a/other-subpath';
88+
89+
export function initializeService(url: string): ServiceConfig {
90+
return createServiceConfig(url);
91+
}
92+
93+
export const factory = createServiceConfig;
94+
95+
export interface AppConfig {
96+
service: ServiceConfig;
97+
debug: boolean;
98+
}
99+
100+
101+
//// [index.js]
102+
"use strict";
103+
Object.defineProperty(exports, "__esModule", { value: true });
104+
exports.factory = void 0;
105+
exports.initializeService = initializeService;
106+
const other_subpath_1 = require("package-a/other-subpath");
107+
function initializeService(url) {
108+
return (0, other_subpath_1.createServiceConfig)(url);
109+
}
110+
exports.factory = other_subpath_1.createServiceConfig;
111+
112+
113+
//// [index.d.ts]
114+
import type { ServiceConfig } from 'package-a/other-subpath';
115+
import { createServiceConfig } from 'package-a/other-subpath';
116+
export declare function initializeService(url: string): ServiceConfig;
117+
export declare const factory: typeof createServiceConfig;
118+
export interface AppConfig {
119+
service: ServiceConfig;
120+
debug: boolean;
121+
}
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+

0 commit comments

Comments
 (0)