Skip to content

Commit ea22fb7

Browse files
authored
Merge pull request #610 from lddubeau/fix/relative-config-path
Allow resolving @types that name libraries in node_modules directories above cwd
2 parents e21b636 + 2551704 commit ea22fb7

40 files changed

+253
-5
lines changed

gulpfile.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const gulp = require('gulp');
22
const rimraf = require('rimraf');
33
const fs = require('fs');
4+
const childProcess = require('child_process');
45
const path = require('path');
56
const mergeStream = require('merge-stream');
67
const ts = require('./release/main');
@@ -36,6 +37,23 @@ const tests = fs.readdirSync(path.join(__dirname, 'test')).filter(function(dir)
3637
return dir !== 'baselines' && dir !== 'output' && dir.substr(0, 1) !== '.';
3738
});
3839

40+
// Some issues with path computations can only be detected with
41+
// `gulp-typescript` running in a process that has a specific cwd. In the test
42+
// suite, such tests have a `gulpfile.js` in their top directory.
43+
const execTests = tests.filter(function(dir) {
44+
const fullPath = path.join('test', dir, 'gulpfile.js');
45+
try {
46+
fs.accessSync(fullPath);
47+
return true;
48+
}
49+
catch (ex) {
50+
if (ex.code !== "ENOENT") {
51+
throw ex;
52+
}
53+
return false;
54+
}
55+
});
56+
3957
// Clean
4058
function clean(cb) {
4159
rimraf(paths.releaseBeta, cb);
@@ -134,11 +152,31 @@ async function runTest(name) {
134152
}));
135153
}
136154

137-
gulp.task('test-run', gulp.series('clean-test', async function testRun() {
155+
async function runExecTest(testName) {
156+
const testDir = path.posix.join('test', testName);
157+
158+
return new Promise((resolve, reject) => {
159+
childProcess.execFile("gulp", {
160+
cwd: testDir,
161+
}, (err) => {
162+
if (err) {
163+
reject(err);
164+
}
165+
resolve();
166+
});
167+
});
168+
}
169+
170+
gulp.task('test-run', gulp.series('clean-test', async () => {
138171
fs.mkdirSync('test/output/');
172+
for (const testName of execTests) {
173+
await runExecTest(testName);
174+
}
175+
139176
for (const testName of tests) {
140177
await runTest(testName);
141178
}
179+
142180
}));
143181

144182
/**

lib/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ module compile {
219219
getTsconfigSystem(typescript),
220220
path.resolve(projectDirectory),
221221
compilerOptions,
222-
path.basename(tsConfigFileName));
222+
tsConfigFileName);
223223

224224
rawConfig = parsed.raw;
225225

lib/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function src(this: Project) {
126126
this.typescript.sys,
127127
path.resolve(this.projectDirectory),
128128
undefined,
129-
path.basename(this.configFileName));
129+
this.configFileName);
130130

131131
for (const error of errors) {
132132
console.log(error.messageText);

release/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function reportErrors(errors, typescript, ignore = []) {
132132
if (tsConfig.error) {
133133
console.log(tsConfig.error.messageText);
134134
}
135-
let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, path.basename(tsConfigFileName));
135+
let parsed = typescript.parseJsonConfigFileContent(tsConfig.config || {}, getTsconfigSystem(typescript), path.resolve(projectDirectory), compilerOptions, tsConfigFileName);
136136
rawConfig = parsed.raw;
137137
tsConfigContent = parsed.raw;
138138
if (parsed.errors) {

release/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function src() {
7676
base = path.resolve(this.projectDirectory, this.options["rootDir"]);
7777
}
7878
const _a = this.rawConfig, { extends: _extends } = _a, config = __rest(_a, ["extends"]);
79-
const { fileNames, errors } = this.typescript.parseJsonConfigFileContent(config, this.typescript.sys, path.resolve(this.projectDirectory), undefined, path.basename(this.configFileName));
79+
const { fileNames, errors } = this.typescript.parseJsonConfigFileContent(config, this.typescript.sys, path.resolve(this.projectDirectory), undefined, this.configFileName);
8080
for (const error of errors) {
8181
console.log(error.messageText);
8282
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class Hello {
2+
value: string;
3+
}

test/baselines/typesResolution/2.3/dts/test-3.d.ts

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"transpileErrors": 0,
3+
"optionsErrors": 0,
4+
"syntaxErrors": 0,
5+
"globalErrors": 0,
6+
"semanticErrors": 0,
7+
"declarationErrors": 0,
8+
"emitErrors": 0,
9+
"emitSkipped": false
10+
}

test/baselines/typesResolution/2.3/js/other-3.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.3/js/other-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.3/js/test-3.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.3/js/test-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class Hello {
2+
value: string;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"transpileErrors": 0,
3+
"optionsErrors": 0,
4+
"syntaxErrors": 0,
5+
"globalErrors": 0,
6+
"semanticErrors": 0,
7+
"declarationErrors": 0,
8+
"emitErrors": 0,
9+
"emitSkipped": false
10+
}

test/baselines/typesResolution/2.7/js/other-3.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.7/js/other-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.7/js/test-3.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.7/js/test-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class Hello {
2+
value: string;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"transpileErrors": 0,
3+
"optionsErrors": 0,
4+
"syntaxErrors": 0,
5+
"globalErrors": 0,
6+
"semanticErrors": 0,
7+
"declarationErrors": 0,
8+
"emitErrors": 0,
9+
"emitSkipped": false
10+
}

test/baselines/typesResolution/2.9/js/other-3.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.9/js/other-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.9/js/test-3.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/2.9/js/test-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class Hello {
2+
value: string;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"transpileErrors": 0,
3+
"optionsErrors": 0,
4+
"syntaxErrors": 0,
5+
"globalErrors": 0,
6+
"semanticErrors": 0,
7+
"declarationErrors": 0,
8+
"emitErrors": 0,
9+
"emitSkipped": false
10+
}

test/baselines/typesResolution/dev/js/other-3.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/dev/js/other-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/dev/js/test-3.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/baselines/typesResolution/dev/js/test-3.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/typesResolution/bad.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blargh.

test/typesResolution/gulpfile.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var gulp = require('gulp');
2+
var newTS = require('../../release-2/main');
3+
var lib = require('../../typescript/dev');
4+
5+
//
6+
// This is a minimal gulpfile designed to cause the error reported in #563. It
7+
// does not produce output because we don't need the output.
8+
//
9+
// This gulpfile must be executed with a `gulp` process lauched with its `cwd`
10+
// set to the directory that contains this gulpfile. Launching it from the
11+
// `gulp-typescript` project root **WILL NOT** trigger the conditions that cause
12+
// the problem.
13+
//
14+
15+
gulp.task('default', function () {
16+
var tsProject = newTS.createProject('./sub/tsconfig.json', {
17+
typescript: lib,
18+
});
19+
20+
return tsProject.src()
21+
.pipe(tsProject());
22+
});

test/typesResolution/gulptask.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var gulp = require('gulp');
2+
var sourcemaps = require('gulp-sourcemaps');
3+
4+
module.exports = function(newTS, lib, output, reporter) {
5+
var tsProject = newTS.createProject('test/typesResolution/sub/tsconfig.json', {
6+
typescript: lib,
7+
});
8+
9+
var tsResult = tsProject.src()
10+
.pipe(sourcemaps.init())
11+
.pipe(tsProject(reporter))
12+
.on('error', () => {});
13+
14+
tsResult.dts.pipe(gulp.dest(output + '/dts'));
15+
return tsResult.js
16+
.pipe(sourcemaps.write('.', { sourceRoot: '../../../../basic/' }))
17+
.pipe(gulp.dest(output + 'js'));
18+
}

test/typesResolution/other-3.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class Hello {
2+
value: string;
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig",
3+
"compilerOptions": {
4+
"types": ["node"]
5+
},
6+
"files": [
7+
"other-3.ts"
8+
]
9+
}

test/typesResolution/test-3.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import other = require('./other-3');
2+
3+
var a = new other.Hello();
4+
console.log(a.value);

test/typesResolution/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"module": "amd",
5+
"types": []
6+
},
7+
"include": [
8+
"test-3.ts"
9+
]
10+
}

0 commit comments

Comments
 (0)