Skip to content

Commit

Permalink
Merge pull request #610 from lddubeau/fix/relative-config-path
Browse files Browse the repository at this point in the history
Allow resolving @types that name libraries in node_modules directories above cwd
  • Loading branch information
ivogabe authored Feb 15, 2019
2 parents e21b636 + 2551704 commit ea22fb7
Show file tree
Hide file tree
Showing 40 changed files with 253 additions and 5 deletions.
40 changes: 39 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const gulp = require('gulp');
const rimraf = require('rimraf');
const fs = require('fs');
const childProcess = require('child_process');
const path = require('path');
const mergeStream = require('merge-stream');
const ts = require('./release/main');
Expand Down Expand Up @@ -36,6 +37,23 @@ const tests = fs.readdirSync(path.join(__dirname, 'test')).filter(function(dir)
return dir !== 'baselines' && dir !== 'output' && dir.substr(0, 1) !== '.';
});

// Some issues with path computations can only be detected with
// `gulp-typescript` running in a process that has a specific cwd. In the test
// suite, such tests have a `gulpfile.js` in their top directory.
const execTests = tests.filter(function(dir) {
const fullPath = path.join('test', dir, 'gulpfile.js');
try {
fs.accessSync(fullPath);
return true;
}
catch (ex) {
if (ex.code !== "ENOENT") {
throw ex;
}
return false;
}
});

// Clean
function clean(cb) {
rimraf(paths.releaseBeta, cb);
Expand Down Expand Up @@ -134,11 +152,31 @@ async function runTest(name) {
}));
}

gulp.task('test-run', gulp.series('clean-test', async function testRun() {
async function runExecTest(testName) {
const testDir = path.posix.join('test', testName);

return new Promise((resolve, reject) => {
childProcess.execFile("gulp", {
cwd: testDir,
}, (err) => {
if (err) {
reject(err);
}
resolve();
});
});
}

gulp.task('test-run', gulp.series('clean-test', async () => {
fs.mkdirSync('test/output/');
for (const testName of execTests) {
await runExecTest(testName);
}

for (const testName of tests) {
await runTest(testName);
}

}));

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ module compile {
getTsconfigSystem(typescript),
path.resolve(projectDirectory),
compilerOptions,
path.basename(tsConfigFileName));
tsConfigFileName);

rawConfig = parsed.raw;

Expand Down
2 changes: 1 addition & 1 deletion lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function src(this: Project) {
this.typescript.sys,
path.resolve(this.projectDirectory),
undefined,
path.basename(this.configFileName));
this.configFileName);

for (const error of errors) {
console.log(error.messageText);
Expand Down
2 changes: 1 addition & 1 deletion release/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function reportErrors(errors, typescript, ignore = []) {
if (tsConfig.error) {
console.log(tsConfig.error.messageText);
}
let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, path.basename(tsConfigFileName));
let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, tsConfigFileName);
rawConfig = parsed.raw;
tsConfigContent = parsed.raw;
if (parsed.errors) {
Expand Down
2 changes: 1 addition & 1 deletion release/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function src() {
base = path.resolve(this.projectDirectory, this.options["rootDir"]);
}
const _a = this.rawConfig, { extends: _extends } = _a, config = __rest(_a, ["extends"]);
const { fileNames, errors } = this.typescript.parseJsonConfigFileContent(config, this.typescript.sys, path.resolve(this.projectDirectory), undefined, path.basename(this.configFileName));
const { fileNames, errors } = this.typescript.parseJsonConfigFileContent(config, this.typescript.sys, path.resolve(this.projectDirectory), undefined, this.configFileName);
for (const error of errors) {
console.log(error.messageText);
}
Expand Down
3 changes: 3 additions & 0 deletions test/baselines/typesResolution/2.3/dts/other-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Hello {
value: string;
}
Empty file.
10 changes: 10 additions & 0 deletions test/baselines/typesResolution/2.3/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 0,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
12 changes: 12 additions & 0 deletions test/baselines/typesResolution/2.3/js/other-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.3/js/other-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/baselines/typesResolution/2.3/js/test-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.3/js/test-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/baselines/typesResolution/2.7/dts/other-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Hello {
value: string;
}
1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.7/dts/test-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
10 changes: 10 additions & 0 deletions test/baselines/typesResolution/2.7/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 0,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
12 changes: 12 additions & 0 deletions test/baselines/typesResolution/2.7/js/other-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.7/js/other-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/baselines/typesResolution/2.7/js/test-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.7/js/test-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/baselines/typesResolution/2.9/dts/other-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Hello {
value: string;
}
1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.9/dts/test-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
10 changes: 10 additions & 0 deletions test/baselines/typesResolution/2.9/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 0,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
12 changes: 12 additions & 0 deletions test/baselines/typesResolution/2.9/js/other-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.9/js/other-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/baselines/typesResolution/2.9/js/test-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/2.9/js/test-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/baselines/typesResolution/dev/dts/other-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class Hello {
value: string;
}
1 change: 1 addition & 0 deletions test/baselines/typesResolution/dev/dts/test-3.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
10 changes: 10 additions & 0 deletions test/baselines/typesResolution/dev/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"transpileErrors": 0,
"optionsErrors": 0,
"syntaxErrors": 0,
"globalErrors": 0,
"semanticErrors": 0,
"declarationErrors": 0,
"emitErrors": 0,
"emitSkipped": false
}
12 changes: 12 additions & 0 deletions test/baselines/typesResolution/dev/js/other-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/dev/js/other-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/baselines/typesResolution/dev/js/test-3.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/baselines/typesResolution/dev/js/test-3.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/typesResolution/bad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blargh.
22 changes: 22 additions & 0 deletions test/typesResolution/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var gulp = require('gulp');
var newTS = require('../../release-2/main');
var lib = require('../../typescript/dev');

//
// This is a minimal gulpfile designed to cause the error reported in #563. It
// does not produce output because we don't need the output.
//
// This gulpfile must be executed with a `gulp` process lauched with its `cwd`
// set to the directory that contains this gulpfile. Launching it from the
// `gulp-typescript` project root **WILL NOT** trigger the conditions that cause
// the problem.
//

gulp.task('default', function () {
var tsProject = newTS.createProject('./sub/tsconfig.json', {
typescript: lib,
});

return tsProject.src()
.pipe(tsProject());
});
18 changes: 18 additions & 0 deletions test/typesResolution/gulptask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');

module.exports = function(newTS, lib, output, reporter) {
var tsProject = newTS.createProject('test/typesResolution/sub/tsconfig.json', {
typescript: lib,
});

var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject(reporter))
.on('error', () => {});

tsResult.dts.pipe(gulp.dest(output + '/dts'));
return tsResult.js
.pipe(sourcemaps.write('.', { sourceRoot: '../../../../basic/' }))
.pipe(gulp.dest(output + 'js'));
}
3 changes: 3 additions & 0 deletions test/typesResolution/other-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class Hello {
value: string;
}
9 changes: 9 additions & 0 deletions test/typesResolution/sub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"types": ["node"]
},
"files": [
"other-3.ts"
]
}
4 changes: 4 additions & 0 deletions test/typesResolution/test-3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import other = require('./other-3');

var a = new other.Hello();
console.log(a.value);
10 changes: 10 additions & 0 deletions test/typesResolution/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"declaration": true,
"module": "amd",
"types": []
},
"include": [
"test-3.ts"
]
}

0 comments on commit ea22fb7

Please sign in to comment.