From 8509fc101a0298b7b4289c4f9eedcbb5d5011214 Mon Sep 17 00:00:00 2001 From: Max Heiber Date: Wed, 10 Apr 2019 12:34:05 +0100 Subject: [PATCH 1/2] add useFileCompiler setting enables getting type-checking while enforcing --isolatedModules fix https://github.com/ivogabe/gulp-typescript/issues/613 --- lib/main.ts | 113 +++++++++++------- lib/project.ts | 17 ++- readme.md | 5 +- release/main.d.ts | 8 +- release/main.js | 78 ++++++------ release/project.d.ts | 2 +- release/project.js | 15 ++- test/baselines/useFileCompiler/2.3/errors.txt | 12 ++ .../2.3/js/excluded-dir/test.js | 3 + .../2.3/js/excluded-dir/test.js.map | 1 + .../useFileCompiler/2.3/js/excluded-file.js | 3 + .../2.3/js/excluded-file.js.map | 1 + .../useFileCompiler/2.3/js/other-3.js | 11 ++ .../useFileCompiler/2.3/js/other-3.js.map | 1 + .../useFileCompiler/2.3/js/test-3.js | 8 ++ .../useFileCompiler/2.3/js/test-3.js.map | 1 + test/baselines/useFileCompiler/2.7/errors.txt | 12 ++ .../useFileCompiler/2.7/js/other-3.js | 12 ++ .../useFileCompiler/2.7/js/test-3.js | 8 ++ test/baselines/useFileCompiler/2.9/errors.txt | 12 ++ .../useFileCompiler/2.9/js/other-3.js | 12 ++ .../useFileCompiler/2.9/js/test-3.js | 8 ++ test/baselines/useFileCompiler/dev/errors.txt | 12 ++ .../useFileCompiler/dev/js/other-3.js | 12 ++ .../useFileCompiler/dev/js/test-3.js | 8 ++ test/useFileCompiler/excluded-dir/test.ts | 1 + test/useFileCompiler/excluded-file.ts | 1 + test/useFileCompiler/gulptask.js | 22 ++++ test/useFileCompiler/other-3.ts | 7 ++ test/useFileCompiler/test-3.ts | 5 + test/useFileCompiler/tsconfig.json | 7 ++ typescript/2.3 | 2 +- 32 files changed, 324 insertions(+), 96 deletions(-) create mode 100644 test/baselines/useFileCompiler/2.3/errors.txt create mode 100644 test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js create mode 100644 test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js.map create mode 100644 test/baselines/useFileCompiler/2.3/js/excluded-file.js create mode 100644 test/baselines/useFileCompiler/2.3/js/excluded-file.js.map create mode 100644 test/baselines/useFileCompiler/2.3/js/other-3.js create mode 100644 test/baselines/useFileCompiler/2.3/js/other-3.js.map create mode 100644 test/baselines/useFileCompiler/2.3/js/test-3.js create mode 100644 test/baselines/useFileCompiler/2.3/js/test-3.js.map create mode 100644 test/baselines/useFileCompiler/2.7/errors.txt create mode 100644 test/baselines/useFileCompiler/2.7/js/other-3.js create mode 100644 test/baselines/useFileCompiler/2.7/js/test-3.js create mode 100644 test/baselines/useFileCompiler/2.9/errors.txt create mode 100644 test/baselines/useFileCompiler/2.9/js/other-3.js create mode 100644 test/baselines/useFileCompiler/2.9/js/test-3.js create mode 100644 test/baselines/useFileCompiler/dev/errors.txt create mode 100644 test/baselines/useFileCompiler/dev/js/other-3.js create mode 100644 test/baselines/useFileCompiler/dev/js/test-3.js create mode 100644 test/useFileCompiler/excluded-dir/test.ts create mode 100644 test/useFileCompiler/excluded-file.ts create mode 100644 test/useFileCompiler/gulptask.js create mode 100644 test/useFileCompiler/other-3.ts create mode 100644 test/useFileCompiler/test-3.ts create mode 100644 test/useFileCompiler/tsconfig.json diff --git a/lib/main.ts b/lib/main.ts index a758c0c0..a48be88c 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -59,7 +59,11 @@ function getFinalTransformers(getCustomTransformers?: GetCustomTransformers): Fi return null; } -function getTypeScript(typescript: typeof ts) { +function getTypeScript(settingsTs: typeof ts, gulpTsSettingsTs: typeof ts) { + if (settingsTs && gulpTsSettingsTs && settingsTs !== gulpTsSettingsTs) { + throw Error("settings.typescript and gulpTsSettings.typescript aren't equal. Please specify only one or use the same `typescript` for both."); + } + const typescript = settingsTs || gulpTsSettingsTs; if (typescript) return typescript; try { return require('typescript'); @@ -166,80 +170,99 @@ module compile { // Unsupported by gulp-typescript sourceRoot?: string; // Use sourceRoot in gulp-sourcemaps instead } + + export interface GulpTsSettings { + useFileCompiler?: boolean; + typescript?: typeof ts; + } + export type Project = _project.Project; export type CompileStream = _project.ICompileStream; export import reporter = _reporter; - export function createProject(tsConfigFileName: string, settings?: Settings): Project; - export function createProject(settings?: Settings): Project; - export function createProject(fileNameOrSettings?: string | Settings, settings?: Settings): Project { + function _createProject({ + tsConfigFileName, + settings, + gulpTsSettings + }: { + tsConfigFileName: string | undefined; + settings: Settings; + gulpTsSettings: GulpTsSettings; + }): Project { let finalTransformers: FinalTransformers; - let tsConfigFileName: string = undefined; let tsConfigContent: TsConfig = undefined; let projectDirectory = process.cwd(); let typescript: typeof ts; let compilerOptions: ts.CompilerOptions; let projectReferences: ReadonlyArray; - let fileName: string; let rawConfig: any; - if (fileNameOrSettings !== undefined) { - if (typeof fileNameOrSettings === 'string') { - fileName = fileNameOrSettings; - tsConfigFileName = path.resolve(process.cwd(), fileName); - projectDirectory = path.dirname(tsConfigFileName); - if (settings === undefined) settings = {}; - } else { - settings = fileNameOrSettings || {}; - } - - finalTransformers = getFinalTransformers(settings.getCustomTransformers); + finalTransformers = getFinalTransformers(settings.getCustomTransformers); - typescript = getTypeScript(settings.typescript); - settings = checkAndNormalizeSettings(settings); + typescript = getTypeScript(settings.typescript, gulpTsSettings.typescript); + settings = checkAndNormalizeSettings(settings); - const settingsResult = typescript.convertCompilerOptionsFromJson(settings, projectDirectory); - - if (settingsResult.errors) { - reportErrors(settingsResult.errors, typescript); - } + const settingsResult = typescript.convertCompilerOptionsFromJson(settings, projectDirectory); - compilerOptions = settingsResult.options; + if (settingsResult.errors) { + reportErrors(settingsResult.errors, typescript); + } - if (fileName !== undefined) { - let tsConfig = typescript.readConfigFile(tsConfigFileName, typescript.sys.readFile); - if (tsConfig.error) { - console.log(tsConfig.error.messageText); - } + compilerOptions = settingsResult.options; - let parsed: ts.ParsedCommandLine = - typescript.parseJsonConfigFileContent( - tsConfig.config || {}, - getTsconfigSystem(typescript), - path.resolve(projectDirectory), - compilerOptions, - tsConfigFileName); + if (tsConfigFileName !== undefined) { + let tsConfig = typescript.readConfigFile(tsConfigFileName, typescript.sys.readFile); + if (tsConfig.error) { + console.log(tsConfig.error.messageText); + } - rawConfig = parsed.raw; + let parsed: ts.ParsedCommandLine = + typescript.parseJsonConfigFileContent( + tsConfig.config || {}, + getTsconfigSystem(typescript), + path.resolve(projectDirectory), + compilerOptions, + tsConfigFileName); - tsConfigContent = parsed.raw; + rawConfig = parsed.raw; - if (parsed.errors) { - reportErrors(parsed.errors, typescript, [18003]); - } + tsConfigContent = parsed.raw; - compilerOptions = parsed.options; - projectReferences = parsed.projectReferences; + if (parsed.errors) { + reportErrors(parsed.errors, typescript, [18003]); } + + compilerOptions = parsed.options; + projectReferences = parsed.projectReferences; } normalizeCompilerOptions(compilerOptions, typescript); - const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript, finalTransformers); + const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript, finalTransformers, gulpTsSettings.useFileCompiler); return project; } + export function createProject(tsConfigFileName: string, settings?: Settings, gulpTsSettings?: GulpTsSettings): Project; + export function createProject(settings?: Settings, gulpTsSettings?: GulpTsSettings): Project; + + export function createProject(fileNameOrSettings?: string | Settings, settingsOrGulpTsSettings?: Settings | GulpTsSettings, gulpTsSettingsParam?: GulpTsSettings): Project { + // overload: createProject(tsConfigFileName, settings, gulpTsSettings) + if (typeof fileNameOrSettings === 'string') { + return _createProject({ + tsConfigFileName: fileNameOrSettings, + settings: settingsOrGulpTsSettings || {}, + gulpTsSettings: gulpTsSettingsParam || {} } + ); + } + // overload: createProject(settings, gulpTsSettings) + return _createProject({ + tsConfigFileName: undefined, + settings: fileNameOrSettings || {}, + gulpTsSettings: settingsOrGulpTsSettings as GulpTsSettings || {} } + ); + } + export function filter(...args: any[]) { utils.deprecate('ts.filter() is deprecated', 'soon you can use tsProject.resolve()', diff --git a/lib/project.ts b/lib/project.ts index a9674a51..4901175b 100644 --- a/lib/project.ts +++ b/lib/project.ts @@ -50,17 +50,24 @@ export interface ProjectInfo { reporter: Reporter; } -export function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, projectReferences: ReadonlyArray, typescript: typeof ts, finalTransformers: FinalTransformers) { +export function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, projectReferences: ReadonlyArray, typescript: typeof ts, finalTransformers: FinalTransformers, useFileCompiler: boolean | undefined) { const input = new FileCache(typescript, options); - const compiler: ICompiler = options.isolatedModules ? new FileCompiler() : new ProjectCompiler(); - let running = false; + if (useFileCompiler && !options.isolatedModules) { + throw Error("useFileCompiler: true can only be used if config.compilerOptions.isolatedModules is also set to true"); + } + let compiler: ICompiler; - if (options.isolatedModules) { + if (options.isolatedModules && (useFileCompiler === undefined || useFileCompiler === true)) { + compiler = new FileCompiler(); options.newLine = typescript.NewLineKind.LineFeed; options.sourceMap = false; options.declaration = false; options.inlineSourceMap = true; - } + } + else { + compiler = new ProjectCompiler(); + } + let running = false; const project: PartialProject = (reporter) => { if (running) { diff --git a/readme.md b/readme.md index 8f8e4c76..071ae5c5 100644 --- a/readme.md +++ b/readme.md @@ -44,7 +44,7 @@ Almost all options from TypeScript are supported. - `noEmitOnError` (boolean) - Do not emit outputs if any type checking errors were reported. - `noEmitHelpers` (boolean) - Do not generate custom helper functions like __extends in compiled output. - `preserveConstEnums` (boolean) - Do not erase const enum declarations in generated code. -- `isolatedModules` (boolean) - Compiles files seperately and doesn't check types, which causes a big speed increase. You have to use gulp-plumber and TypeScript 1.5+. +- `isolatedModules` (boolean) - By default, this option compiles files seperately and doesn't check types, which causes a big speed increase. You have to use gulp-plumber and TypeScript 1.5+. If you use the `createProject` API (see below) and specify `useFileCompiler: false`, the meaning changes to match that of `tsc`. That is, you *will* get type-checking at the cost of slower compilation. In addition, TypeScript will error on constructs that would prevent safe separate compilation. - `allowJs` (boolean) - Allow JavaScript files to be compiled. - `rootDir` - Specifies the root directory of input files. Only use to control the output directory structure with `outDir`. @@ -60,7 +60,8 @@ API overview gulp-typescript can be imported using `const ts = require('gulp-typescript');`. It provides the following functions: - `ts(options?)` - Returns a gulp stream that compiles TypeScript files using the specified options. -- `ts.createProject(options?)`, `ts.createProject(tsconfig filename, options?)` - Returns a project. The intended usage is to create a project outside of a task with `const tsProject = ts.createProject(..);`. Within a task, `tsProject()` can be used to compile a stream of TypeScript files. +- `ts.createProject(options?)`, `ts.createProject(tsconfig filename?: string, options?: CompilerOptions, gulpTsOptions?: GulpTsOptions)` - Returns a project. The intended usage is to create a project outside of a task with `const tsProject = ts.createProject(..);`. Within a task, `tsProject()` can be used to compile a stream of TypeScript files. The shape of `GulpTsOptions` is `{ useFileCompiler: boolean, typescript: TS }`. `useFileCompiler` defaults to `true` when `isolatedModules` is `true`. Specify `useFileCompiler: false` to use the project compiler even if `isolatedModules` is `true`. +> The important differences are that the project compiler does type checking but the file compiler is faster and more more memory-efficient. Using `isolatedModules` and `useFileCompiler: false` together does extra type-checking that ensures that `useFileCompiler: true` *would* be safe. - `tsProject.src()` - Returns a stream containing the source files (.ts) from a tsconfig file. It can only be used if you create a project with a `tsconfig.json` file. It is a replacement for `gulp.src(..)`. Both `ts(..)` and `tsProject()` provide sub-streams that only contain the JavaScript or declaration files. An example is shown later in the readme. diff --git a/release/main.d.ts b/release/main.d.ts index bf567735..80904a09 100644 --- a/release/main.d.ts +++ b/release/main.d.ts @@ -41,11 +41,15 @@ declare module compile { [name: string]: any; sourceRoot?: string; } + interface GulpTsSettings { + useFileCompiler?: boolean; + typescript?: typeof ts; + } type Project = _project.Project; type CompileStream = _project.ICompileStream; export import reporter = _reporter; - function createProject(tsConfigFileName: string, settings?: Settings): Project; - function createProject(settings?: Settings): Project; + function createProject(tsConfigFileName: string, settings?: Settings, gulpTsSettings?: GulpTsSettings): Project; + function createProject(settings?: Settings, gulpTsSettings?: GulpTsSettings): Project; function filter(...args: any[]): void; } export = compile; diff --git a/release/main.js b/release/main.js index 38224361..751b9af8 100644 --- a/release/main.js +++ b/release/main.js @@ -49,7 +49,11 @@ function getFinalTransformers(getCustomTransformers) { } return null; } -function getTypeScript(typescript) { +function getTypeScript(settingsTs, gulpTsSettingsTs) { + if (settingsTs && gulpTsSettingsTs && settingsTs !== gulpTsSettingsTs) { + throw Error("settings.typescript and gulpTsSettings.typescript aren't equal. Please specify only one or use the same `typescript` for both."); + } + const typescript = settingsTs || gulpTsSettingsTs; if (typescript) return typescript; try { @@ -98,54 +102,56 @@ function reportErrors(errors, typescript, ignore = []) { } (function (compile) { compile.reporter = _reporter; - function createProject(fileNameOrSettings, settings) { + function _createProject({ tsConfigFileName, settings, gulpTsSettings }) { let finalTransformers; - let tsConfigFileName = undefined; let tsConfigContent = undefined; let projectDirectory = process.cwd(); let typescript; let compilerOptions; let projectReferences; - let fileName; let rawConfig; - if (fileNameOrSettings !== undefined) { - if (typeof fileNameOrSettings === 'string') { - fileName = fileNameOrSettings; - tsConfigFileName = path.resolve(process.cwd(), fileName); - projectDirectory = path.dirname(tsConfigFileName); - if (settings === undefined) - settings = {}; - } - else { - settings = fileNameOrSettings || {}; - } - finalTransformers = getFinalTransformers(settings.getCustomTransformers); - typescript = getTypeScript(settings.typescript); - settings = checkAndNormalizeSettings(settings); - const settingsResult = typescript.convertCompilerOptionsFromJson(settings, projectDirectory); - if (settingsResult.errors) { - reportErrors(settingsResult.errors, typescript); + finalTransformers = getFinalTransformers(settings.getCustomTransformers); + typescript = getTypeScript(settings.typescript, gulpTsSettings.typescript); + settings = checkAndNormalizeSettings(settings); + const settingsResult = typescript.convertCompilerOptionsFromJson(settings, projectDirectory); + if (settingsResult.errors) { + reportErrors(settingsResult.errors, typescript); + } + compilerOptions = settingsResult.options; + if (tsConfigFileName !== undefined) { + let tsConfig = typescript.readConfigFile(tsConfigFileName, typescript.sys.readFile); + if (tsConfig.error) { + console.log(tsConfig.error.messageText); } - compilerOptions = settingsResult.options; - if (fileName !== undefined) { - let tsConfig = typescript.readConfigFile(tsConfigFileName, typescript.sys.readFile); - if (tsConfig.error) { - console.log(tsConfig.error.messageText); - } - let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, tsConfigFileName); - rawConfig = parsed.raw; - tsConfigContent = parsed.raw; - if (parsed.errors) { - reportErrors(parsed.errors, typescript, [18003]); - } - compilerOptions = parsed.options; - projectReferences = parsed.projectReferences; + let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, tsConfigFileName); + rawConfig = parsed.raw; + tsConfigContent = parsed.raw; + if (parsed.errors) { + reportErrors(parsed.errors, typescript, [18003]); } + compilerOptions = parsed.options; + projectReferences = parsed.projectReferences; } normalizeCompilerOptions(compilerOptions, typescript); - const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript, finalTransformers); + const project = _project.setupProject(projectDirectory, tsConfigFileName, rawConfig, tsConfigContent, compilerOptions, projectReferences, typescript, finalTransformers, gulpTsSettings.useFileCompiler); return project; } + function createProject(fileNameOrSettings, settingsOrGulpTsSettings, gulpTsSettingsParam) { + // overload: createProject(tsConfigFileName, settings, gulpTsSettings) + if (typeof fileNameOrSettings === 'string') { + return _createProject({ + tsConfigFileName: fileNameOrSettings, + settings: settingsOrGulpTsSettings || {}, + gulpTsSettings: gulpTsSettingsParam || {} + }); + } + // overload: createProject(settings, gulpTsSettings) + return _createProject({ + tsConfigFileName: undefined, + settings: fileNameOrSettings || {}, + gulpTsSettings: settingsOrGulpTsSettings || {} + }); + } compile.createProject = createProject; function filter(...args) { utils.deprecate('ts.filter() is deprecated', 'soon you can use tsProject.resolve()', 'Filters have been removed as of gulp-typescript 3.0.\nSoon tsProject.resolve() will be available as an alternative.\nSee https://github.com/ivogabe/gulp-typescript/issues/190.'); diff --git a/release/project.d.ts b/release/project.d.ts index e5787d64..0c51b6ec 100644 --- a/release/project.d.ts +++ b/release/project.d.ts @@ -28,7 +28,7 @@ export interface ProjectInfo { directory: string; reporter: Reporter; } -export declare function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, projectReferences: ReadonlyArray, typescript: typeof ts, finalTransformers: FinalTransformers): Project; +export declare function setupProject(projectDirectory: string, configFileName: string, rawConfig: any, config: TsConfig, options: ts.CompilerOptions, projectReferences: ReadonlyArray, typescript: typeof ts, finalTransformers: FinalTransformers, useFileCompiler: boolean | undefined): Project; export interface ICompileStream extends NodeJS.ReadWriteStream { js: stream.Readable; dts: stream.Readable; diff --git a/release/project.js b/release/project.js index 3d9b855c..7d09122c 100644 --- a/release/project.js +++ b/release/project.js @@ -18,16 +18,23 @@ const reporter_1 = require("./reporter"); const input_1 = require("./input"); const output_1 = require("./output"); const compiler_1 = require("./compiler"); -function setupProject(projectDirectory, configFileName, rawConfig, config, options, projectReferences, typescript, finalTransformers) { +function setupProject(projectDirectory, configFileName, rawConfig, config, options, projectReferences, typescript, finalTransformers, useFileCompiler) { const input = new input_1.FileCache(typescript, options); - const compiler = options.isolatedModules ? new compiler_1.FileCompiler() : new compiler_1.ProjectCompiler(); - let running = false; - if (options.isolatedModules) { + if (useFileCompiler && !options.isolatedModules) { + throw Error("useFileCompiler: true can only be used if config.compilerOptions.isolatedModules is also set to true"); + } + let compiler; + if (options.isolatedModules && (useFileCompiler === undefined || useFileCompiler === true)) { + compiler = new compiler_1.FileCompiler(); options.newLine = typescript.NewLineKind.LineFeed; options.sourceMap = false; options.declaration = false; options.inlineSourceMap = true; } + else { + compiler = new compiler_1.ProjectCompiler(); + } + let running = false; const project = (reporter) => { if (running) { throw new Error('gulp-typescript: A project cannot be used in two compilations at the same time. Create multiple projects with createProject instead.'); diff --git a/test/baselines/useFileCompiler/2.3/errors.txt b/test/baselines/useFileCompiler/2.3/errors.txt new file mode 100644 index 00000000..838e360d --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/errors.txt @@ -0,0 +1,12 @@ +TypeScript error: test/useFileCompiler/excluded-dir/test.ts(1,1): error TS2304: Cannot find name 'notCompiled'. +TypeScript error: test/useFileCompiler/excluded-file.ts(1,1): error TS2304: Cannot find name 'notCompiled'. +{ + "transpileErrors": 0, + "optionsErrors": 0, + "syntaxErrors": 0, + "globalErrors": 0, + "semanticErrors": 2, + "declarationErrors": 0, + "emitErrors": 0, + "emitSkipped": false +} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js b/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js new file mode 100644 index 00000000..7a9bab32 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js @@ -0,0 +1,3 @@ +notCompiled; + +//# sourceMappingURL=test.js.map diff --git a/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js.map b/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js.map new file mode 100644 index 00000000..1ea2b295 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/excluded-dir/test.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["excluded-dir/test.ts"],"names":[],"mappings":"AAAA,WAAW,CAAC","file":"test.js","sourcesContent":["notCompiled;"],"sourceRoot":"../../../../../useFileCompiler/"} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.3/js/excluded-file.js b/test/baselines/useFileCompiler/2.3/js/excluded-file.js new file mode 100644 index 00000000..d8165d15 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/excluded-file.js @@ -0,0 +1,3 @@ +notCompiled; + +//# sourceMappingURL=excluded-file.js.map diff --git a/test/baselines/useFileCompiler/2.3/js/excluded-file.js.map b/test/baselines/useFileCompiler/2.3/js/excluded-file.js.map new file mode 100644 index 00000000..130e6a4d --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/excluded-file.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["excluded-file.ts"],"names":[],"mappings":"AAAA,WAAW,CAAC","file":"excluded-file.js","sourcesContent":["notCompiled;"],"sourceRoot":"../../../../useFileCompiler/"} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.3/js/other-3.js b/test/baselines/useFileCompiler/2.3/js/other-3.js new file mode 100644 index 00000000..f4a531d9 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/other-3.js @@ -0,0 +1,11 @@ +"use strict"; +exports.__esModule = true; +var Klass = (function () { + function Klass() { + } + return Klass; +}()); +exports.Klass = Klass; +exports.value = 3; + +//# sourceMappingURL=other-3.js.map diff --git a/test/baselines/useFileCompiler/2.3/js/other-3.js.map b/test/baselines/useFileCompiler/2.3/js/other-3.js.map new file mode 100644 index 00000000..882b26d6 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/other-3.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["other-3.ts"],"names":[],"mappings":";;AAAA;IAAA;IAEA,CAAC;IAAD,YAAC;AAAD,CAFA,AAEC,IAAA;AAFY,sBAAK;AAIL,QAAA,KAAK,GAAG,CAAC,CAAC","file":"other-3.js","sourcesContent":["export class Klass {\n\tvalue: string;\n}\n\nexport const value = 3;\n\nexport type Alias = number;"],"sourceRoot":"../../../../useFileCompiler/"} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.3/js/test-3.js b/test/baselines/useFileCompiler/2.3/js/test-3.js new file mode 100644 index 00000000..4a4db8d9 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/test-3.js @@ -0,0 +1,8 @@ +"use strict"; +exports.__esModule = true; +var other_3_1 = require("./other-3"); +exports.Klass = other_3_1.Klass; +exports.value = other_3_1.value; +var n = other_3_1.value; + +//# sourceMappingURL=test-3.js.map diff --git a/test/baselines/useFileCompiler/2.3/js/test-3.js.map b/test/baselines/useFileCompiler/2.3/js/test-3.js.map new file mode 100644 index 00000000..213e65d2 --- /dev/null +++ b/test/baselines/useFileCompiler/2.3/js/test-3.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["test-3.ts"],"names":[],"mappings":";;AAAA,qCAAgD;AAIhC,gBAJA,eAAK,CAIA;AAAE,gBAJA,eAAK,CAIA;AAF5B,IAAM,CAAC,GAAU,eAAK,CAAC","file":"test-3.js","sourcesContent":["import { Alias, Klass, value } from \"./other-3\";\n\nconst n: Alias = value;\n\nexport { Alias, Klass, value };"],"sourceRoot":"../../../../useFileCompiler/"} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.7/errors.txt b/test/baselines/useFileCompiler/2.7/errors.txt new file mode 100644 index 00000000..14e242ab --- /dev/null +++ b/test/baselines/useFileCompiler/2.7/errors.txt @@ -0,0 +1,12 @@ +TypeScript error: error TS5053: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +TypeScript error: test/useFileCompiler/test-3.ts(5,10): error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided. +{ + "transpileErrors": 0, + "optionsErrors": 1, + "syntaxErrors": 0, + "globalErrors": 0, + "semanticErrors": 1, + "declarationErrors": 0, + "emitErrors": 0, + "emitSkipped": false +} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.7/js/other-3.js b/test/baselines/useFileCompiler/2.7/js/other-3.js new file mode 100644 index 00000000..0e0d4beb --- /dev/null +++ b/test/baselines/useFileCompiler/2.7/js/other-3.js @@ -0,0 +1,12 @@ +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var Klass = /** @class */ (function () { + function Klass() { + } + return Klass; + }()); + exports.Klass = Klass; + exports.value = 3; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3RoZXItMy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm90aGVyLTMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0lBQUE7UUFBQTtRQUVBLENBQUM7UUFBRCxZQUFDO0lBQUQsQ0FBQyxBQUZELElBRUM7SUFGWSxzQkFBSztJQUlMLFFBQUEsS0FBSyxHQUFHLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.7/js/test-3.js b/test/baselines/useFileCompiler/2.7/js/test-3.js new file mode 100644 index 00000000..e14bba09 --- /dev/null +++ b/test/baselines/useFileCompiler/2.7/js/test-3.js @@ -0,0 +1,8 @@ +define(["require", "exports", "./other-3"], function (require, exports, other_3_1) { + "use strict"; + exports.__esModule = true; + exports.Klass = other_3_1.Klass; + exports.value = other_3_1.value; + var n = other_3_1.value; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC0zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidGVzdC0zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztJQUlnQixnQkFKQSxlQUFLLENBSUE7SUFBRSxnQkFKQSxlQUFLLENBSUE7SUFGNUIsSUFBTSxDQUFDLEdBQVUsZUFBSyxDQUFDIn0= \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.9/errors.txt b/test/baselines/useFileCompiler/2.9/errors.txt new file mode 100644 index 00000000..14e242ab --- /dev/null +++ b/test/baselines/useFileCompiler/2.9/errors.txt @@ -0,0 +1,12 @@ +TypeScript error: error TS5053: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +TypeScript error: test/useFileCompiler/test-3.ts(5,10): error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided. +{ + "transpileErrors": 0, + "optionsErrors": 1, + "syntaxErrors": 0, + "globalErrors": 0, + "semanticErrors": 1, + "declarationErrors": 0, + "emitErrors": 0, + "emitSkipped": false +} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.9/js/other-3.js b/test/baselines/useFileCompiler/2.9/js/other-3.js new file mode 100644 index 00000000..0e0d4beb --- /dev/null +++ b/test/baselines/useFileCompiler/2.9/js/other-3.js @@ -0,0 +1,12 @@ +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var Klass = /** @class */ (function () { + function Klass() { + } + return Klass; + }()); + exports.Klass = Klass; + exports.value = 3; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3RoZXItMy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm90aGVyLTMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0lBQUE7UUFBQTtRQUVBLENBQUM7UUFBRCxZQUFDO0lBQUQsQ0FBQyxBQUZELElBRUM7SUFGWSxzQkFBSztJQUlMLFFBQUEsS0FBSyxHQUFHLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/test/baselines/useFileCompiler/2.9/js/test-3.js b/test/baselines/useFileCompiler/2.9/js/test-3.js new file mode 100644 index 00000000..e14bba09 --- /dev/null +++ b/test/baselines/useFileCompiler/2.9/js/test-3.js @@ -0,0 +1,8 @@ +define(["require", "exports", "./other-3"], function (require, exports, other_3_1) { + "use strict"; + exports.__esModule = true; + exports.Klass = other_3_1.Klass; + exports.value = other_3_1.value; + var n = other_3_1.value; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC0zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidGVzdC0zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztJQUlnQixnQkFKQSxlQUFLLENBSUE7SUFBRSxnQkFKQSxlQUFLLENBSUE7SUFGNUIsSUFBTSxDQUFDLEdBQVUsZUFBSyxDQUFDIn0= \ No newline at end of file diff --git a/test/baselines/useFileCompiler/dev/errors.txt b/test/baselines/useFileCompiler/dev/errors.txt new file mode 100644 index 00000000..14e242ab --- /dev/null +++ b/test/baselines/useFileCompiler/dev/errors.txt @@ -0,0 +1,12 @@ +TypeScript error: error TS5053: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +TypeScript error: test/useFileCompiler/test-3.ts(5,10): error TS1205: Cannot re-export a type when the '--isolatedModules' flag is provided. +{ + "transpileErrors": 0, + "optionsErrors": 1, + "syntaxErrors": 0, + "globalErrors": 0, + "semanticErrors": 1, + "declarationErrors": 0, + "emitErrors": 0, + "emitSkipped": false +} \ No newline at end of file diff --git a/test/baselines/useFileCompiler/dev/js/other-3.js b/test/baselines/useFileCompiler/dev/js/other-3.js new file mode 100644 index 00000000..0e0d4beb --- /dev/null +++ b/test/baselines/useFileCompiler/dev/js/other-3.js @@ -0,0 +1,12 @@ +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + var Klass = /** @class */ (function () { + function Klass() { + } + return Klass; + }()); + exports.Klass = Klass; + exports.value = 3; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3RoZXItMy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIm90aGVyLTMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0lBQUE7UUFBQTtRQUVBLENBQUM7UUFBRCxZQUFDO0lBQUQsQ0FBQyxBQUZELElBRUM7SUFGWSxzQkFBSztJQUlMLFFBQUEsS0FBSyxHQUFHLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/test/baselines/useFileCompiler/dev/js/test-3.js b/test/baselines/useFileCompiler/dev/js/test-3.js new file mode 100644 index 00000000..e14bba09 --- /dev/null +++ b/test/baselines/useFileCompiler/dev/js/test-3.js @@ -0,0 +1,8 @@ +define(["require", "exports", "./other-3"], function (require, exports, other_3_1) { + "use strict"; + exports.__esModule = true; + exports.Klass = other_3_1.Klass; + exports.value = other_3_1.value; + var n = other_3_1.value; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC0zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidGVzdC0zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztJQUlnQixnQkFKQSxlQUFLLENBSUE7SUFBRSxnQkFKQSxlQUFLLENBSUE7SUFGNUIsSUFBTSxDQUFDLEdBQVUsZUFBSyxDQUFDIn0= \ No newline at end of file diff --git a/test/useFileCompiler/excluded-dir/test.ts b/test/useFileCompiler/excluded-dir/test.ts new file mode 100644 index 00000000..f4a01510 --- /dev/null +++ b/test/useFileCompiler/excluded-dir/test.ts @@ -0,0 +1 @@ +notCompiled; \ No newline at end of file diff --git a/test/useFileCompiler/excluded-file.ts b/test/useFileCompiler/excluded-file.ts new file mode 100644 index 00000000..f4a01510 --- /dev/null +++ b/test/useFileCompiler/excluded-file.ts @@ -0,0 +1 @@ +notCompiled; \ No newline at end of file diff --git a/test/useFileCompiler/gulptask.js b/test/useFileCompiler/gulptask.js new file mode 100644 index 00000000..1346d742 --- /dev/null +++ b/test/useFileCompiler/gulptask.js @@ -0,0 +1,22 @@ +var gulp = require('gulp'); +var sourcemaps = require('gulp-sourcemaps'); +var plumber = require('gulp-plumber'); + +module.exports = function(newTS, lib, output, reporter) { + var tsProject = newTS.createProject('test/useFileCompiler/tsconfig.json', { + typescript: lib, + }, { + useFileCompiler: false + }); + + var tsResult = tsProject.src() + .pipe(plumber()) + .pipe(sourcemaps.init()) + .pipe(tsProject(reporter)) + .on('error', () => {}); + + tsResult.dts.pipe(gulp.dest(output + '/dts')); + return tsResult.js + .pipe(sourcemaps.write('.', { sourceRoot: '../../../../useFileCompiler/' })) + .pipe(gulp.dest(output + 'js')); +} diff --git a/test/useFileCompiler/other-3.ts b/test/useFileCompiler/other-3.ts new file mode 100644 index 00000000..4a11b83e --- /dev/null +++ b/test/useFileCompiler/other-3.ts @@ -0,0 +1,7 @@ +export class Klass { + value: string; +} + +export const value = 3; + +export type Alias = number; \ No newline at end of file diff --git a/test/useFileCompiler/test-3.ts b/test/useFileCompiler/test-3.ts new file mode 100644 index 00000000..a83197c2 --- /dev/null +++ b/test/useFileCompiler/test-3.ts @@ -0,0 +1,5 @@ +import { Alias, Klass, value } from "./other-3"; + +const n: Alias = value; + +export { Alias, Klass, value }; \ No newline at end of file diff --git a/test/useFileCompiler/tsconfig.json b/test/useFileCompiler/tsconfig.json new file mode 100644 index 00000000..1710f453 --- /dev/null +++ b/test/useFileCompiler/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "amd", + "isolatedModules": true, + }, + "exclude": ["excluded-file.ts", "excluded-dir"] +} diff --git a/typescript/2.3 b/typescript/2.3 index 1a579d92..3902ef78 160000 --- a/typescript/2.3 +++ b/typescript/2.3 @@ -1 +1 @@ -Subproject commit 1a579d929f1d0ee4d45de7cee505970a24a40cc7 +Subproject commit 3902ef78ae0204534ce9ebff93ee1a77175cd62c From 8b278320a828a2af2a0a4d86bbdddb62c54362ab Mon Sep 17 00:00:00 2001 From: Max Heiber Date: Mon, 19 Aug 2019 13:36:50 +0100 Subject: [PATCH 2/2] update ts thing --- lib/main.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/main.ts b/lib/main.ts index a48be88c..890e5699 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -59,11 +59,7 @@ function getFinalTransformers(getCustomTransformers?: GetCustomTransformers): Fi return null; } -function getTypeScript(settingsTs: typeof ts, gulpTsSettingsTs: typeof ts) { - if (settingsTs && gulpTsSettingsTs && settingsTs !== gulpTsSettingsTs) { - throw Error("settings.typescript and gulpTsSettings.typescript aren't equal. Please specify only one or use the same `typescript` for both."); - } - const typescript = settingsTs || gulpTsSettingsTs; +function getTypeScript(typescript: typeof ts) { if (typescript) return typescript; try { return require('typescript'); @@ -155,7 +151,6 @@ module compile { sortOutput?: boolean; getCustomTransformers?: GetCustomTransformers; - typescript?: typeof ts; isolatedModules?: boolean;