Skip to content

Commit

Permalink
Add inline typescript sources to transformed output (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil authored Jan 19, 2022
1 parent ba9d3c2 commit 339c004
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/modules/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ internals.transform = function (content, fileName) {
const { options } = Typescript.parseJsonConfigFileContent(config, Typescript.sys, Typescript.getDirectoryPath(configFile), {}, configFile);
options.sourceMap = false;
options.inlineSourceMap = true;
options.module = 1; // CommonJS
options.inlineSources = true;
options.module = Typescript.ModuleKind.CommonJS;
internals.configs.set(configFile, options);
}

Expand Down
18 changes: 18 additions & 0 deletions test/typescript.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';

const Fs = require('fs');
const Path = require('path');

const Code = require('@hapi/code');
const _Lab = require('../test_runner');
const RunCli = require('./run_cli');
const Typescript = require('../lib/modules/typescript');


const internals = {
Expand Down Expand Up @@ -37,4 +39,20 @@ describe('TypeScript', () => {
expect(result.code).to.equal(1);
expect(result.output).to.contain('error.ts:10:26');
});

describe('transform', () => {

it('generates embedded sourcemap with sourcesContent', () => {

const smre = /\/\/\#\s*sourceMappingURL=data:application\/json[^,]+base64,(.*)\r?\n?$/;
const path = Path.join(__dirname, 'cli_typescript', 'simple.ts');
const transformed = Typescript.extensions[0].transform(Fs.readFileSync(path, { encoding: 'utf8' }), path);
const matches = smre.exec(transformed);
expect(matches).to.exist();
const sourcemap = JSON.parse(Buffer.from(matches[1], 'base64').toString());
expect(sourcemap.sources).to.equal(['simple.ts']);
expect(sourcemap.sourcesContent).to.exist();
expect(sourcemap.sourcesContent).to.have.length(1);
});
});
});

0 comments on commit 339c004

Please sign in to comment.