Add tsconfig option to specify tsconfig path (#8452)
* Add tsconfig option to specify tsconfig path * Add CHANGELOG entry and fix lint * Add a test * Fix test
This commit is contained in:
parent
574a6a104d
commit
d9dd88c740
|
@ -18,7 +18,10 @@
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
- [codegen/typescript] - Respect default values in Pulumi object types.
|
- [cli/nodejs] - Allow specifying the tsconfig file used in Pulumi.yaml.
|
||||||
|
[#8452](https://github.com/pulumi/pulumi/pull/8452)
|
||||||
|
|
||||||
|
- [codegen/nodejs] - Respect default values in Pulumi object types.
|
||||||
[#8400](https://github.com/pulumi/pulumi/pull/8400)
|
[#8400](https://github.com/pulumi/pulumi/pull/8400)
|
||||||
|
|
||||||
- [sdk/python] - Correctly handle version checking python virtual environments.
|
- [sdk/python] - Correctly handle version checking python virtual environments.
|
||||||
|
|
|
@ -82,11 +82,14 @@ func main() {
|
||||||
var tracing string
|
var tracing string
|
||||||
var typescript bool
|
var typescript bool
|
||||||
var root string
|
var root string
|
||||||
|
var tsconfigpath string
|
||||||
flag.StringVar(&tracing, "tracing", "",
|
flag.StringVar(&tracing, "tracing", "",
|
||||||
"Emit tracing to a Zipkin-compatible tracing endpoint")
|
"Emit tracing to a Zipkin-compatible tracing endpoint")
|
||||||
flag.BoolVar(&typescript, "typescript", true,
|
flag.BoolVar(&typescript, "typescript", true,
|
||||||
"Use ts-node at runtime to support typescript source natively")
|
"Use ts-node at runtime to support typescript source natively")
|
||||||
flag.StringVar(&root, "root", "", "Project root path to use")
|
flag.StringVar(&root, "root", "", "Project root path to use")
|
||||||
|
flag.StringVar(&tsconfigpath, "tsconfig", "",
|
||||||
|
"Path to tsconfig.json to use")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
|
@ -118,7 +121,7 @@ func main() {
|
||||||
// Fire up a gRPC server, letting the kernel choose a free port.
|
// Fire up a gRPC server, letting the kernel choose a free port.
|
||||||
port, done, err := rpcutil.Serve(0, nil, []func(*grpc.Server) error{
|
port, done, err := rpcutil.Serve(0, nil, []func(*grpc.Server) error{
|
||||||
func(srv *grpc.Server) error {
|
func(srv *grpc.Server) error {
|
||||||
host := newLanguageHost(nodePath, runPath, engineAddress, tracing, typescript)
|
host := newLanguageHost(nodePath, runPath, engineAddress, tracing, typescript, tsconfigpath)
|
||||||
pulumirpc.RegisterLanguageRuntimeServer(srv, host)
|
pulumirpc.RegisterLanguageRuntimeServer(srv, host)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -155,16 +158,18 @@ type nodeLanguageHost struct {
|
||||||
engineAddress string
|
engineAddress string
|
||||||
tracing string
|
tracing string
|
||||||
typescript bool
|
typescript bool
|
||||||
|
tsconfigpath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLanguageHost(nodePath, runPath, engineAddress,
|
func newLanguageHost(nodePath, runPath, engineAddress,
|
||||||
tracing string, typescript bool) pulumirpc.LanguageRuntimeServer {
|
tracing string, typescript bool, tsconfigpath string) pulumirpc.LanguageRuntimeServer {
|
||||||
return &nodeLanguageHost{
|
return &nodeLanguageHost{
|
||||||
nodeBin: nodePath,
|
nodeBin: nodePath,
|
||||||
runPath: runPath,
|
runPath: runPath,
|
||||||
engineAddress: engineAddress,
|
engineAddress: engineAddress,
|
||||||
tracing: tracing,
|
tracing: tracing,
|
||||||
typescript: typescript,
|
typescript: typescript,
|
||||||
|
tsconfigpath: tsconfigpath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,6 +509,9 @@ func (host *nodeLanguageHost) execNodejs(
|
||||||
if host.typescript {
|
if host.typescript {
|
||||||
env = append(env, "PULUMI_NODEJS_TYPESCRIPT=true")
|
env = append(env, "PULUMI_NODEJS_TYPESCRIPT=true")
|
||||||
}
|
}
|
||||||
|
if host.tsconfigpath != "" {
|
||||||
|
env = append(env, "PULUMI_NODEJS_TSCONFIG_PATH="+host.tsconfigpath)
|
||||||
|
}
|
||||||
|
|
||||||
if logging.V(5) {
|
if logging.V(5) {
|
||||||
commandStr := strings.Join(args, " ")
|
commandStr := strings.Join(args, " ")
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { parseConfigFileTextToJson } from "typescript";
|
||||||
import { ResourceError, RunError } from "../../errors";
|
import { ResourceError, RunError } from "../../errors";
|
||||||
import * as log from "../../log";
|
import * as log from "../../log";
|
||||||
import * as runtime from "../../runtime";
|
import * as runtime from "../../runtime";
|
||||||
|
import { Inputs } from "../../output";
|
||||||
|
|
||||||
import * as mod from ".";
|
import * as mod from ".";
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ function throwOrPrintModuleLoadError(program: string, error: Error): void {
|
||||||
const deps = packageObject["dependencies"] || {};
|
const deps = packageObject["dependencies"] || {};
|
||||||
const devDeps = packageObject["devDependencies"] || {};
|
const devDeps = packageObject["devDependencies"] || {};
|
||||||
const scripts = packageObject["scripts"] || {};
|
const scripts = packageObject["scripts"] || {};
|
||||||
const mainProperty = packageObject["main"] || "index.js";
|
const mainProperty = packageObject["main"] || "index.js";
|
||||||
|
|
||||||
// Is there a build script associated with this program? It's a little confusing that the
|
// Is there a build script associated with this program? It's a little confusing that the
|
||||||
// Pulumi CLI doesn't run build scripts before running the program so call that out
|
// Pulumi CLI doesn't run build scripts before running the program so call that out
|
||||||
|
@ -106,7 +107,7 @@ function throwOrPrintModuleLoadError(program: string, error: Error): void {
|
||||||
const command = scripts["build"];
|
const command = scripts["build"];
|
||||||
console.error(` * Your program looks like it has a build script associated with it ('${command}').\n`);
|
console.error(` * Your program looks like it has a build script associated with it ('${command}').\n`);
|
||||||
console.error("Pulumi does not run build scripts before running your program. " +
|
console.error("Pulumi does not run build scripts before running your program. " +
|
||||||
`Please run '${command}', 'yarn build', or 'npm run build' and try again.`);
|
`Please run '${command}', 'yarn build', or 'npm run build' and try again.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +133,11 @@ function throwOrPrintModuleLoadError(program: string, error: Error): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export function run(argv: minimist.ParsedArgs,
|
export function run(
|
||||||
programStarted: () => void,
|
argv: minimist.ParsedArgs,
|
||||||
reportLoggedError: (err: Error) => void,
|
programStarted: () => void,
|
||||||
isErrorReported: (err: Error) => boolean) {
|
reportLoggedError: (err: Error) => void,
|
||||||
|
isErrorReported: (err: Error) => boolean): Promise<Inputs | undefined> {
|
||||||
// If there is a --pwd directive, switch directories.
|
// If there is a --pwd directive, switch directories.
|
||||||
const pwd: string | undefined = argv["pwd"];
|
const pwd: string | undefined = argv["pwd"];
|
||||||
if (pwd) {
|
if (pwd) {
|
||||||
|
@ -150,7 +152,8 @@ export function run(argv: minimist.ParsedArgs,
|
||||||
// find a tsconfig.json. For us, it's reasonable to say that the "root" of the project is the cwd,
|
// find a tsconfig.json. For us, it's reasonable to say that the "root" of the project is the cwd,
|
||||||
// if there's a tsconfig.json file here. Otherwise, just tell ts-node to not load project options at all.
|
// if there's a tsconfig.json file here. Otherwise, just tell ts-node to not load project options at all.
|
||||||
// This helps with cases like pulumi/pulumi#1772.
|
// This helps with cases like pulumi/pulumi#1772.
|
||||||
const tsConfigPath = "tsconfig.json";
|
const defaultTsConfigPath = "tsconfig.json";
|
||||||
|
const tsConfigPath: string = process.env["PULUMI_NODEJS_TSCONFIG_PATH"] ?? defaultTsConfigPath;
|
||||||
const skipProject = !fs.existsSync(tsConfigPath);
|
const skipProject = !fs.existsSync(tsConfigPath);
|
||||||
|
|
||||||
let compilerOptions: object;
|
let compilerOptions: object;
|
||||||
|
@ -184,7 +187,7 @@ export function run(argv: minimist.ParsedArgs,
|
||||||
|
|
||||||
// Now fake out the process-wide argv, to make the program think it was run normally.
|
// Now fake out the process-wide argv, to make the program think it was run normally.
|
||||||
const programArgs: string[] = argv._.slice(1);
|
const programArgs: string[] = argv._.slice(1);
|
||||||
process.argv = [ process.argv[0], process.argv[1], ...programArgs ];
|
process.argv = [process.argv[0], process.argv[1], ...programArgs];
|
||||||
|
|
||||||
// Set up the process uncaught exception, unhandled rejection, and program exit handlers.
|
// Set up the process uncaught exception, unhandled rejection, and program exit handlers.
|
||||||
const uncaughtHandler = (err: Error) => {
|
const uncaughtHandler = (err: Error) => {
|
||||||
|
@ -230,6 +233,15 @@ ${defaultMessage}`);
|
||||||
|
|
||||||
programStarted();
|
programStarted();
|
||||||
|
|
||||||
|
// This needs to occur after `programStarted` to ensure execution of the parent process stops.
|
||||||
|
if (skipProject && tsConfigPath !== defaultTsConfigPath) {
|
||||||
|
return new Promise(() => {
|
||||||
|
const e = new Error(`tsconfig path was set to ${tsConfigPath} but the file was not found`);
|
||||||
|
e.stack = undefined;
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const runProgram = async () => {
|
const runProgram = async () => {
|
||||||
// We run the program inside this context so that it adopts all resources.
|
// We run the program inside this context so that it adopts all resources.
|
||||||
//
|
//
|
||||||
|
|
|
@ -1178,3 +1178,23 @@ func TestAboutNodeJS(t *testing.T) {
|
||||||
func TestConstructOutputValuesNode(t *testing.T) {
|
func TestConstructOutputValuesNode(t *testing.T) {
|
||||||
testConstructOutputValues(t, "nodejs", "@pulumi/pulumi")
|
testConstructOutputValues(t, "nodejs", "@pulumi/pulumi")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTSConfigOption(t *testing.T) {
|
||||||
|
if runtime.GOOS == WindowsOS {
|
||||||
|
t.Skip("Skip on windows because we lack yarn")
|
||||||
|
}
|
||||||
|
|
||||||
|
e := ptesting.NewEnvironment(t)
|
||||||
|
defer func() {
|
||||||
|
if !t.Failed() {
|
||||||
|
e.DeleteEnvironment()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
e.ImportDirectory("tsconfig")
|
||||||
|
|
||||||
|
e.RunCommand("yarn", "link", "@pulumi/pulumi")
|
||||||
|
e.RunCommand("yarn", "install")
|
||||||
|
e.RunCommand("pulumi", "login", "--cloud-url", e.LocalURL())
|
||||||
|
e.RunCommand("pulumi", "stack", "select", "tsconfg", "--create")
|
||||||
|
e.RunCommand("pulumi", "preview")
|
||||||
|
}
|
||||||
|
|
5
tests/integration/tsconfig/Pulumi.yaml
Normal file
5
tests/integration/tsconfig/Pulumi.yaml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
name: test-yaml-option
|
||||||
|
runtime:
|
||||||
|
name: nodejs
|
||||||
|
options:
|
||||||
|
tsconfig: other.json
|
7
tests/integration/tsconfig/index.ts
Normal file
7
tests/integration/tsconfig/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
|
||||||
|
// If this is run onder "module": "esnext", it will fail. Neither the import nor the export are
|
||||||
|
// valid for "esnext".
|
||||||
|
|
||||||
|
// Export the name of the bucket
|
||||||
|
export const bucketName = "name";
|
16
tests/integration/tsconfig/other.json
Normal file
16
tests/integration/tsconfig/other.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"outDir": "bin",
|
||||||
|
"target": "es2016",
|
||||||
|
"module": "commonjs",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"pretty": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": ["index.ts"]
|
||||||
|
}
|
9
tests/integration/tsconfig/package.json
Normal file
9
tests/integration/tsconfig/package.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "tsconfig",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^14"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pulumi/pulumi": "^3.0.0"
|
||||||
|
}
|
||||||
|
}
|
16
tests/integration/tsconfig/tsconfig.json
Normal file
16
tests/integration/tsconfig/tsconfig.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"outDir": "bin",
|
||||||
|
"target": "es2016",
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"pretty": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": ["index.ts"]
|
||||||
|
}
|
Loading…
Reference in a new issue