gulp-typescript
gulp-typescript copied to clipboard
Wrong module name
Expected behavior:
I'm not sure where the issue comes from.
But here is the output from what I'm expecting. Look closely at the Contents with the define("module-name" I want that the module name is sub/path/testFile
> gulp MyTask -LLLL
[17:00:42] Using gulpfile [...project-folder...]\gulpfile.js
[17:00:42] Starting 'MyTask'...
========================================================
========================================================
Path: \test\sub\path\testFile.ts Relative: sub\path\testFile.ts
Base: \test Basename: testFile.ts
Extname: .ts Dirname: \test\sub\path
Cwd: \ History: [ '\\test\\sub\\path\\testFile.ts' ]
Contents: export const test = 'value';
========================================================
========================================================
========================================================
Path: [...project-folder...]\dist\js\bundle.js Relative: dist\js\bundle.js
Base: [...project-folder...] Basename: bundle.js
Extname: .js Dirname: [...project-folder...]\dist\js
Cwd: \ History: [ '[...project-folder...]\\dist\\js\\bundle.js' ]
Contents: define("sub/path/testFile", ["require", "exports"], function (require, exports) {
"use strict";
exports.__esModule = true;
exports.test = 'value';
});
========================================================
[17:00:46] Finished 'MyTask' after 3.57 s
Actual behavior:
This is the actual output. Look closely at the Contents with the define("module-name"
> gulp MyTask -LLLL
[17:00:42] Using gulpfile [...project-folder...]\gulpfile.js
[17:00:42] Starting 'MyTask'...
========================================================
========================================================
Path: \test\sub\path\testFile.ts Relative: sub\path\testFile.ts
Base: \test Basename: testFile.ts
Extname: .ts Dirname: \test\sub\path
Cwd: \ History: [ '\\test\\sub\\path\\testFile.ts' ]
Contents: export const test = 'value';
========================================================
========================================================
========================================================
Path: [...project-folder...]\dist\js\bundle.js Relative: dist\js\bundle.js
Base: [...project-folder...] Basename: bundle.js
Extname: .js Dirname: [...project-folder...]\dist\js
Cwd: \ History: [ '[...project-folder...]\\dist\\js\\bundle.js' ]
Contents: define("testFile", ["require", "exports"], function (require, exports) {
"use strict";
exports.__esModule = true;
exports.test = 'value';
});
========================================================
[17:00:46] Finished 'MyTask' after 3.57 s
Your gulpfile:
Include your gulpfile, or only the related task (with ts.createProject).
const gulp = require('gulp');
const ts = require('gulp-typescript');
const vinyl = require('vinyl');
const stream = require("stream");
const through2 = require("through2");
// TypeScript Helper Function
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
// CustomStream Class
var CustomStream = (function (_super) {
__extends(CustomStream, _super);
function CustomStream() {
return _super.call(this, { objectMode: true }) || this;
}
CustomStream.prototype._read = function () {
};
return CustomStream;
}(stream.Readable));
// Debug
const debug = function () {
return through2.obj(function (file, enc, callback) {
console.log('========================================================');
console.log('========================================================');
console.log('Path:', file.path, 'Relative:', file.relative);
console.log('Base:', file.base, 'Basename:', file.basename);
console.log('Extname:', file.extname, 'Dirname:', file.dirname);
console.log('Cwd:', file.cwd, 'History:', file.history);
if (file.contents) {
console.log('Contents:', file.contents.toString());
}
console.log('========================================================');
callback(null, file);
});
};
// My Task
gulp.task(function MyTask() {
const mystream = new CustomStream();
const project = ts.createProject('./tsconfig.json');
var myfile = new vinyl({
cwd: '/',
base: '/test/',
path: '/test/sub/path/testFile.ts',
contents: Buffer.from('export const test = \'value\';')
});
mystream.push(myfile)
mystream.push(null);
return mystream
.pipe(debug())
.pipe(project())
.pipe(debug());
});
tsconfig.json
I also tried some combinations with all the baseUrl, rootDirs, outDir and sourceRoot options.
{
"compilerOptions": {
"module": "amd",
"outFile": "./dist/js/bundle.js",
"baseUrl": "./test",
"rootDirs": ["./test"],
"outDir": "./test",
"sourceRoot": "./test"
}
}
I'm not sure I'm doing anything wrong...
This works... 😄
mystream.push(new vinyl({
cwd: './',
base: './test',
path: './test/path/created/testFile.ts',
contents: Buffer.from('export const test = \'value\';')
}));
mystream.push(new vinyl({
cwd: './',
base: './test',
path: './test/empty.ts',
contents: Buffer.from('')
}));
mystream.push(null);
Sorry for the late reply. Could you try this again with the latest release? We had some changes recently for the handling of those paths, so I hope it is more stable now.