Skip to content

Commit

Permalink
Get output from solutionBuilder for referenced files in transpileOnly…
Browse files Browse the repository at this point in the history
… mode as well
  • Loading branch information
sheetalkamat committed Apr 8, 2020
1 parent bf49856 commit 0561a9f
Show file tree
Hide file tree
Showing 79 changed files with 493 additions and 162 deletions.
21 changes: 17 additions & 4 deletions src/index.ts
Expand Up @@ -536,6 +536,12 @@ function getEmit(
).version
);

return getOutputAndSourceMapFromOutputFiles(outputFiles);
}

function getOutputAndSourceMapFromOutputFiles(
outputFiles: typescript.OutputFile[]
) {
const outputFile = outputFiles
.filter(file => file.name.match(constants.jsJsx))
.pop();
Expand Down Expand Up @@ -630,6 +636,16 @@ function getTranspilationEmit(
instance: TSInstance,
loaderContext: webpack.loader.LoaderContext
) {
if (isReferencedFile(instance, fileName)) {
const outputFiles = instance.solutionBuilderHost!.getOutputFilesFromReferencedProjectInput(
fileName
);
addDependenciesFromSolutionBuilder(instance, fileName, file =>
loaderContext.addDependency(path.resolve(file))
);
return getOutputAndSourceMapFromOutputFiles(outputFiles);
}

const {
outputText,
sourceMapText,
Expand All @@ -646,10 +662,7 @@ function getTranspilationEmit(
);

// _module.errors is not available inside happypack - see https://github.com/TypeStrong/ts-loader/issues/336
if (
!instance.loaderOptions.happyPackMode &&
!isReferencedFile(instance, fileName)
) {
if (!instance.loaderOptions.happyPackMode) {
const errors = formatErrors(
diagnostics,
instance.loaderOptions,
Expand Down
10 changes: 5 additions & 5 deletions src/instances.ts
Expand Up @@ -686,14 +686,14 @@ export function getEmitOutput(instance: TSInstance, filePath: string) {
if (fileExtensionIs(filePath, instance.compiler.Extension.Dts)) {
return [];
}
if (isReferencedFile(instance, filePath)) {
return instance.solutionBuilderHost!.getOutputFilesFromReferencedProjectInput(
filePath
);
}
const program = ensureProgram(instance);
if (program !== undefined) {
const sourceFile = program.getSourceFile(filePath);
if (isReferencedFile(instance, filePath)) {
return instance.solutionBuilderHost!.getOutputFilesFromReferencedProjectInput(
filePath
);
}
const outputFiles: typescript.OutputFile[] = [];
const writeFile = (
fileName: string,
Expand Down
9 changes: 8 additions & 1 deletion test/comparison-tests/create-and-execute-test.js
Expand Up @@ -245,7 +245,14 @@ function storeStats(stats, testState, paths) {

function compareFiles(paths, test, patch) {
if (saveOutputMode) {
copySync(paths.actualOutput, paths.originalExpectedOutput);
const actualFiles = glob.sync('**/*', { cwd: paths.actualOutput, nodir: true });
actualFiles.forEach(function (file) {
const actual = getNormalisedFileContent(file, paths.actualOutput);
const expected = getNormalisedFileContent(file, paths.expectedOutput);
if (actual !== expected) {
fs.copyFileSync(path.join(paths.actualOutput, file), path.join(paths.originalExpectedOutput, file));
}
});
}
else {
// compare actual to expected
Expand Down
Expand Up @@ -106,7 +106,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar li
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.lib = {\n one: 1,\n two: 2,\n three: 3\n};\n\n\n//# sourceURL=webpack:///./lib/index.ts?");
eval("\r\nexports.__esModule = true;\r\nexports.lib = {\r\n one: 1,\r\n two: 2,\r\n three: 3\r\n};\r\n\n\n//# sourceURL=webpack:///./lib/index.ts?");

/***/ })

Expand Down
Expand Up @@ -98,27 +98,14 @@ eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar li

/***/ }),

/***/ "./common/index.ts":
/*!*************************!*\
!*** ./common/index.ts ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction common() {\n return 30;\n}\nexports.common = common;\n\n\n//# sourceURL=webpack:///./common/index.ts?");

/***/ }),

/***/ "./lib/index.ts":
/*!**********************!*\
!*** ./lib/index.ts ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/***/ (function(module, exports) {

"use strict";
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.lib = {\n one: 1,\n two: 2,\n three: 3\n};\n\n\n//# sourceURL=webpack:///./lib/index.ts?");
eval("throw new Error(\"Module build failed (from c:/github/ts-loader/index.js):/nError: TypeScript emitted no output for c://github//ts-loader//.test//projectReferencesMultiple.transpile//lib//index.ts. The most common cause for this is having errors when building referenced projects./n at makeSourceMapAndFinish (c://github//ts-loader//dist//index.js:87:18)/n at successLoader (c://github//ts-loader//dist//index.js:73:9)/n at Object.loader (c://github//ts-loader//dist//index.js:24:5)\");\n\n//# sourceURL=webpack:///./lib/index.ts?");

/***/ }),

Expand All @@ -127,10 +114,9 @@ eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexport
!*** ./utils/index.ts ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
/***/ (function(module, exports) {

"use strict";
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar common_1 = __webpack_require__(/*! ../common */ \"./common/index.ts\");\nfunction utils() {\n common_1.common();\n}\nexports.utils = utils;\n\n\n//# sourceURL=webpack:///./utils/index.ts?");
eval("throw new Error(\"Module build failed (from c:/github/ts-loader/index.js):/nError: TypeScript emitted no output for c://github//ts-loader//.test//projectReferencesMultiple.transpile//utils//index.ts. The most common cause for this is having errors when building referenced projects./n at makeSourceMapAndFinish (c://github//ts-loader//dist//index.js:87:18)/n at successLoader (c://github//ts-loader//dist//index.js:73:9)/n at Object.loader (c://github//ts-loader//dist//index.js:24:5)\");\n\n//# sourceURL=webpack:///./utils/index.ts?");

/***/ })

Expand Down
@@ -1,13 +1,28 @@
Asset Size Chunks Chunk Names
bundle.js 5.35 KiB main [emitted] main
bundle.js 5.57 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 218 bytes {main} [built] [2 errors]
[./common/index.ts] 139 bytes {main} [built]
[./lib/index.ts] 133 bytes {main} [built]
[./utils/index.ts] 181 bytes {main} [built]
[./lib/index.ts] 493 bytes {main} [built] [failed] [1 error]
[./utils/index.ts] 495 bytes {main} [built] [failed] [1 error]

ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in [tsl] ERROR in lib\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in ./lib/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for lib\index.ts. The most common cause for this is having errors when building referenced projects.
at makeSourceMapAndFinish (dist\index.js:87:18)
at successLoader (dist\index.js:73:9)
at Object.loader (dist\index.js:24:5)
@ ./app.ts 3:12-28

ERROR in ./utils/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for utils\index.ts. The most common cause for this is having errors when building referenced projects.
at makeSourceMapAndFinish (dist\index.js:87:18)
at successLoader (dist\index.js:73:9)
at Object.loader (dist\index.js:24:5)
@ ./app.ts 4:14-32
@@ -0,0 +1,124 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./app.ts");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./app.ts":
/*!****************!*\
!*** ./app.ts ***!
\****************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar lib_1 = __webpack_require__(/*! ./lib */ \"./lib/index.ts\");\nvar utils_1 = __webpack_require__(/*! ./utils */ \"./utils/index.ts\");\nconsole.log(lib_1.lib.one, lib_1.lib.two, lib_1.lib.three);\nutils_1.utils();\n\n\n//# sourceURL=webpack:///./app.ts?");

/***/ }),

/***/ "./lib/index.ts":
/*!**********************!*\
!*** ./lib/index.ts ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";
eval("\r\nexports.__esModule = true;\r\nexports.lib = {\r\n one: 1,\r\n two: 2,\r\n three: 3\r\n};\r\n\n\n//# sourceURL=webpack:///./lib/index.ts?");

/***/ }),

/***/ "./utils/index.ts":
/*!************************!*\
!*** ./utils/index.ts ***!
\************************/
/*! no static exports found */
/***/ (function(module, exports) {

eval("throw new Error(\"Module build failed (from c:/github/ts-loader/index.js):/nError: TypeScript emitted no output for c://github//ts-loader//.test//projectReferencesMultiple.transpile//utils//index.ts. The most common cause for this is having errors when building referenced projects./n at makeSourceMapAndFinish (c://github//ts-loader//dist//index.js:87:18)/n at successLoader (c://github//ts-loader//dist//index.js:73:9)/n at Object.loader (c://github//ts-loader//dist//index.js:24:5)\");\n\n//# sourceURL=webpack:///./utils/index.ts?");

/***/ })

/******/ });
@@ -1,10 +1,17 @@
Asset Size Chunks Chunk Names
bundle.js 5.35 KiB main main
Asset Size Chunks Chunk Names
bundle.js 5.19 KiB main [emitted] main
Entrypoint main = bundle.js
[./app.ts] 218 bytes {main} [built] [1 error]
[./common/index.ts] 139 bytes {main}
[./lib/index.ts] 133 bytes {main}
[./utils/index.ts] 181 bytes {main}
[./lib/index.ts] 104 bytes {main} [built]
[./utils/index.ts] 495 bytes {main} [built] [failed] [1 error]

ERROR in [tsl] ERROR in indirectWithError\fileWithError.ts(2,5)
 TS2322: Type 'false' is not assignable to type 'string'.
 TS2322: Type 'false' is not assignable to type 'string'.

ERROR in ./utils/index.ts
Module build failed (from /index.js):
Error: TypeScript emitted no output for utils\index.ts. The most common cause for this is having errors when building referenced projects.
at makeSourceMapAndFinish (dist\index.js:87:18)
at successLoader (dist\index.js:73:9)
at Object.loader (dist\index.js:24:5)
@ ./app.ts 4:14-32

0 comments on commit 0561a9f

Please sign in to comment.