diff --git a/CHANGELOG.md b/CHANGELOG.md index bc06b71b1..125db8680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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://github.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://github.com/TypeStrong/ts-loader/pull/1726) - thanks @johnnyreilly diff --git a/src/diagnostics.ts b/src/diagnostics.ts index 2ab78710b..2b7c044e2 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -60,8 +60,6 @@ export function reportPendingTypeScriptDiagnostics( instance: TSInstance, compilation: webpack.Compilation, getModulesByFile: () => ModulesByFile, - // See getUnrequestedBlocks. - unrequestedBlocks: ReadonlySet, ) { if (instance.pendingDiagnostics.size === 0) { return; @@ -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; } @@ -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, ) { diff --git a/src/index.ts b/src/index.ts index a7a27fb35..717200e78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ import { closeTypeScriptApi, createTypeScriptInstance, getTypeScriptEmit, - getUnrequestedBlocks, + forgetRemovedBlocks, recheckAllTransitiveDependants, recordProgramDiagnostics, restartTypeScriptApiIfDead, @@ -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); @@ -336,7 +338,6 @@ function addPostCompileHooks( instance, compilation, getModulesByFile, - getUnrequestedBlocks(instance, compilation), ); emitPendingDeclarationFiles(instance, compilation); } diff --git a/src/typeScriptApi.ts b/src/typeScriptApi.ts index a2af2857d..d1a3a780a 100644 --- a/src/typeScriptApi.ts +++ b/src/typeScriptApi.ts @@ -28,6 +28,7 @@ import { getPendingModuleKey, isRestoredModuleOfInstance, reportTypeScriptErrors, + wasModuleBuilt, } from './diagnostics'; import type { ErrorFileNames, ModulesByFile } from './diagnostics'; import type { @@ -2758,34 +2759,45 @@ function batchInChunks( } /** - * 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 { +) { + 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(); if (blockLayers.length === 0) { - return unrequestedBlocks; + return; } const toBlockKey = (resourcePath: string, blockName: string) => `${instance.resolvedFilePathCache(resourcePath)}?${blockName}`; const requestedBlocks = new Set(); + const builtFiles = new Set(); // 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)); @@ -2793,12 +2805,21 @@ export function getUnrequestedBlocks( 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; } /** diff --git a/test/comparison-tests/vueBlockGoneWatch/app.ts b/test/comparison-tests/vueBlockGoneWatch/app.ts new file mode 100644 index 000000000..40287e824 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/app.ts @@ -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; diff --git a/test/comparison-tests/vueBlockGoneWatch/block-loader.js b/test/comparison-tests/vueBlockGoneWatch/block-loader.js new file mode 100644 index 000000000..1a40a6b9a --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/block-loader.js @@ -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; +}; diff --git a/test/comparison-tests/vueBlockGoneWatch/component.vue b/test/comparison-tests/vueBlockGoneWatch/component.vue new file mode 100644 index 000000000..234e94e9c --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/component.vue @@ -0,0 +1,5 @@ +export default { name: 'component' }; +// template +export function render(): string { + return 'hello'; +} diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/bundle.js new file mode 100644 index 000000000..80d978208 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/bundle.js @@ -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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/output.txt new file mode 100644 index 000000000..a958c1b22 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/output.txt @@ -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 \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/bundle.js new file mode 100644 index 000000000..06aaba103 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/bundle.js @@ -0,0 +1,106 @@ +/* + * 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\nconst render = undefined;\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ ..._component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__[\"default\"], 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}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // 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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/output.txt new file mode 100644 index 000000000..d43ae5d87 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch0/output.txt @@ -0,0 +1,7 @@ +asset bundle.js 5.07 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cached modules 400 bytes [cached] 1 module +javascript modules 244 bytes + ./component.vue 126 bytes [built] [code generated] + ./component.vue?vue&type=script&lang=ts 118 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/bundle.js new file mode 100644 index 000000000..65e35912c --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/bundle.js @@ -0,0 +1,106 @@ +/* + * 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\nconst render = undefined;\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ ..._component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__[\"default\"], 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}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // 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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/output.txt new file mode 100644 index 000000000..f144cf199 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput-transpile/patch1/output.txt @@ -0,0 +1,5 @@ +asset bundle.js 5.07 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cached modules 244 bytes [cached] 2 modules +./app.ts 406 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/bundle.js new file mode 100644 index 000000000..80d978208 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/bundle.js @@ -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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/output.txt new file mode 100644 index 000000000..a958c1b22 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/output.txt @@ -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 \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/bundle.js new file mode 100644 index 000000000..06aaba103 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/bundle.js @@ -0,0 +1,106 @@ +/* + * 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\nconst render = undefined;\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ ..._component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__[\"default\"], 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}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // 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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/output.txt new file mode 100644 index 000000000..038fb1357 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch0/output.txt @@ -0,0 +1,14 @@ +asset bundle.js 5.07 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cached modules 400 bytes [cached] 1 module +javascript modules 244 bytes + ./component.vue 126 bytes [built] [code generated] + ./component.vue?vue&type=script&lang=ts 118 bytes [built] [code generated] + +ERROR in other.ts +1:28-54 +[tsl] ERROR in other.ts(1,29) + TS2307: Cannot find module './component.vue.template' or its corresponding type declarations. +ts-loader-default_c2d89ce7f76746a5 + +webpack compiled with 1 error \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/bundle.js b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/bundle.js new file mode 100644 index 000000000..65e35912c --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/bundle.js @@ -0,0 +1,106 @@ +/* + * 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\nconst render = undefined;\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ ..._component_vue_vue_type_script_lang_ts__WEBPACK_IMPORTED_MODULE_0__[\"default\"], 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}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // 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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/output.txt b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/output.txt new file mode 100644 index 000000000..9f60cbc70 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/expectedOutput/patch1/output.txt @@ -0,0 +1,12 @@ +asset bundle.js 5.07 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cached modules 244 bytes [cached] 2 modules +./app.ts 406 bytes [built] [code generated] + +ERROR in other.ts +1:28-54 +[tsl] ERROR in other.ts(1,29) + TS2307: Cannot find module './component.vue.template' or its corresponding type declarations. +ts-loader-default_c2d89ce7f76746a5 + +webpack compiled with 1 error \ No newline at end of file diff --git a/test/comparison-tests/vueBlockGoneWatch/facade-loader.js b/test/comparison-tests/vueBlockGoneWatch/facade-loader.js new file mode 100644 index 000000000..1970b214a --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/facade-loader.js @@ -0,0 +1,15 @@ +const path = require('path'); + +// Stands in for what vue-loader makes of the file itself: a module that +// imports each block the file has, as a request for the same file with a query. +module.exports = function (source) { + const request = './' + path.basename(this.resourcePath); + return [ + `import script from ${JSON.stringify(request + '?vue&type=script&lang=ts')};`, + source.includes('// template\n') + ? `import { render } from ${JSON.stringify(request + '?vue&type=template&ts=true')};` + : 'const render = undefined;', + 'export default { ...script, render };', + '' + ].join('\n'); +}; diff --git a/test/comparison-tests/vueBlockGoneWatch/other.ts b/test/comparison-tests/vueBlockGoneWatch/other.ts new file mode 100644 index 000000000..106ed1113 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/other.ts @@ -0,0 +1,3 @@ +import type { render } from './component.vue.template'; + +export type Rendered = ReturnType; diff --git a/test/comparison-tests/vueBlockGoneWatch/patch0/component.vue b/test/comparison-tests/vueBlockGoneWatch/patch0/component.vue new file mode 100644 index 000000000..ccb57ec25 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/patch0/component.vue @@ -0,0 +1 @@ +export default { name: 'component' }; diff --git a/test/comparison-tests/vueBlockGoneWatch/patch1/app.ts b/test/comparison-tests/vueBlockGoneWatch/patch1/app.ts new file mode 100644 index 000000000..73afaa305 --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/patch1/app.ts @@ -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 + '!'; diff --git a/test/comparison-tests/vueBlockGoneWatch/tsconfig.json b/test/comparison-tests/vueBlockGoneWatch/tsconfig.json new file mode 100644 index 000000000..cf4cece4a --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "strict": true + }, + "include": [ + "*.ts" + ] +} diff --git a/test/comparison-tests/vueBlockGoneWatch/webpack.config.js b/test/comparison-tests/vueBlockGoneWatch/webpack.config.js new file mode 100644 index 000000000..0bec3be7d --- /dev/null +++ b/test/comparison-tests/vueBlockGoneWatch/webpack.config.js @@ -0,0 +1,27 @@ +// As vue-loader does, the script and the compiled template of component.vue +// both reach ts-loader, as requests for the same file. other.ts takes a type +// from the template, by the name TypeScript has it under. +// - patch0: component.vue loses its template. Nothing compiles that block +// again, and nothing says it has gone: ts-loader has to work out that it +// has, and take it away from TypeScript. other.ts can no longer find it. +// - patch1: another file changes; the template stays gone. +const options = { appendTsSuffixTo: [/\.vue$/] }; + +module.exports = { + mode: 'development', + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { test: /\.ts$/, loader: 'ts-loader', options }, + { test: /\.vue$/, resourceQuery: /vue/, loader: 'ts-loader', options }, + { test: /\.vue$/, resourceQuery: /vue/, enforce: 'pre', loader: './block-loader.js' }, + { test: /\.vue$/, resourceQuery: { not: [/vue/] }, loader: './facade-loader.js' } + ] + } +} diff --git a/test/comparison-tests/vueFileNotImportedWatch/app.ts b/test/comparison-tests/vueFileNotImportedWatch/app.ts new file mode 100644 index 000000000..eaecbc87d --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/app.ts @@ -0,0 +1,3 @@ +import component from './component.vue'; + +export const app = component.name; diff --git a/test/comparison-tests/vueFileNotImportedWatch/block-loader.js b/test/comparison-tests/vueFileNotImportedWatch/block-loader.js new file mode 100644 index 000000000..1a40a6b9a --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/block-loader.js @@ -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; +}; diff --git a/test/comparison-tests/vueFileNotImportedWatch/component.vue b/test/comparison-tests/vueFileNotImportedWatch/component.vue new file mode 100644 index 000000000..0ff83b97b --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/component.vue @@ -0,0 +1,7 @@ +const name: number = 'component'; + +export default { name }; +// template +export function render(): string { + return 'hello'; +} diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/bundle.js new file mode 100644 index 000000000..cb199b986 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/bundle.js @@ -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 = void 0;\nconst component_vue_1 = __importDefault(__webpack_require__(/*! ./component.vue */ \"./component.vue\"));\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 }));\nconst name = 'component';\nexports[\"default\"] = { name };\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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/output.txt new file mode 100644 index 000000000..6351741a8 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/output.txt @@ -0,0 +1,8 @@ +asset bundle.js 5.76 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cacheable modules 794 bytes + ./app.ts 351 bytes [built] [code generated] + ./component.vue 168 bytes [built] [code generated] + ./component.vue?vue&type=script&lang=ts 131 bytes [built] [code generated] + ./component.vue?vue&type=template&ts=true 144 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/bundle.js new file mode 100644 index 000000000..dcf23218f --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/bundle.js @@ -0,0 +1,33 @@ +/* + * 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 ***! + \****************/ +/***/ ((__unused_webpack_module, exports) => { + +eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.app = void 0;\nexports.app = 'none';\n\n\n//# sourceURL=webpack:///./app.ts?\n}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module can't be inlined because the eval devtool is used. +/******/ var __webpack_exports__ = {}; +/******/ __webpack_modules__["./app.ts"](0, __webpack_exports__); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/output.txt new file mode 100644 index 000000000..b04b07c9f --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch0/output.txt @@ -0,0 +1,3 @@ +asset bundle.js 1.33 KiB [emitted] (name: main) +./app.ts 121 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/bundle.js new file mode 100644 index 000000000..cb199b986 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/bundle.js @@ -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 = void 0;\nconst component_vue_1 = __importDefault(__webpack_require__(/*! ./component.vue */ \"./component.vue\"));\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 }));\nconst name = 'component';\nexports[\"default\"] = { name };\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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/output.txt new file mode 100644 index 000000000..41a4ce07a --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput-transpile/patch1/output.txt @@ -0,0 +1,5 @@ +asset bundle.js 5.76 KiB [emitted] (name: main) +cached modules 443 bytes [cached] 3 modules +runtime modules 670 bytes 3 modules +./app.ts 351 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/bundle.js new file mode 100644 index 000000000..cb199b986 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/bundle.js @@ -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 = void 0;\nconst component_vue_1 = __importDefault(__webpack_require__(/*! ./component.vue */ \"./component.vue\"));\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 }));\nconst name = 'component';\nexports[\"default\"] = { name };\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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/output.txt new file mode 100644 index 000000000..ec3c3208a --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/output.txt @@ -0,0 +1,17 @@ +asset bundle.js 5.76 KiB [emitted] (name: main) +runtime modules 670 bytes 3 modules +cacheable modules 794 bytes + ./app.ts 351 bytes [built] [code generated] + ./component.vue 168 bytes [built] [code generated] + ./component.vue?vue&type=script&lang=ts 131 bytes [built] [code generated] [1 error] + ./component.vue?vue&type=template&ts=true 144 bytes [built] [code generated] + +ERROR in component.vue.ts +./component.vue?vue&type=script&lang=ts 1:6-10 +[tsl] ERROR in component.vue.ts(1,7) + TS2322: Type 'string' is not assignable to type 'number'. +ts-loader-default_c2d89ce7f76746a5 + @ ./component.vue 1:0-61 3:20-26 + @ ./app.ts 7:40-66 + +webpack compiled with 1 error \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/bundle.js new file mode 100644 index 000000000..dcf23218f --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/bundle.js @@ -0,0 +1,33 @@ +/* + * 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 ***! + \****************/ +/***/ ((__unused_webpack_module, exports) => { + +eval("{\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.app = void 0;\nexports.app = 'none';\n\n\n//# sourceURL=webpack:///./app.ts?\n}"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module can't be inlined because the eval devtool is used. +/******/ var __webpack_exports__ = {}; +/******/ __webpack_modules__["./app.ts"](0, __webpack_exports__); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/output.txt new file mode 100644 index 000000000..b04b07c9f --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch0/output.txt @@ -0,0 +1,3 @@ +asset bundle.js 1.33 KiB [emitted] (name: main) +./app.ts 121 bytes [built] [code generated] +webpack compiled successfully \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/bundle.js b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/bundle.js new file mode 100644 index 000000000..cb199b986 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/bundle.js @@ -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 = void 0;\nconst component_vue_1 = __importDefault(__webpack_require__(/*! ./component.vue */ \"./component.vue\"));\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 }));\nconst name = 'component';\nexports[\"default\"] = { name };\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"); +/******/ +/******/ })() +; \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/output.txt b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/output.txt new file mode 100644 index 000000000..1575542ca --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/expectedOutput/patch1/output.txt @@ -0,0 +1,14 @@ +asset bundle.js 5.76 KiB [emitted] (name: main) +cached modules 443 bytes [cached] 3 modules +runtime modules 670 bytes 3 modules +./app.ts 351 bytes [built] [code generated] + +ERROR in component.vue.ts +./component.vue?vue&type=script&lang=ts 1:6-10 +[tsl] ERROR in component.vue.ts(1,7) + TS2322: Type 'string' is not assignable to type 'number'. +ts-loader-default_c2d89ce7f76746a5 + @ ./component.vue 1:0-61 3:20-26 + @ ./app.ts 7:40-66 + +webpack compiled with 1 error \ No newline at end of file diff --git a/test/comparison-tests/vueFileNotImportedWatch/facade-loader.js b/test/comparison-tests/vueFileNotImportedWatch/facade-loader.js new file mode 100644 index 000000000..1970b214a --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/facade-loader.js @@ -0,0 +1,15 @@ +const path = require('path'); + +// Stands in for what vue-loader makes of the file itself: a module that +// imports each block the file has, as a request for the same file with a query. +module.exports = function (source) { + const request = './' + path.basename(this.resourcePath); + return [ + `import script from ${JSON.stringify(request + '?vue&type=script&lang=ts')};`, + source.includes('// template\n') + ? `import { render } from ${JSON.stringify(request + '?vue&type=template&ts=true')};` + : 'const render = undefined;', + 'export default { ...script, render };', + '' + ].join('\n'); +}; diff --git a/test/comparison-tests/vueFileNotImportedWatch/patch0/app.ts b/test/comparison-tests/vueFileNotImportedWatch/patch0/app.ts new file mode 100644 index 000000000..06259f258 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/patch0/app.ts @@ -0,0 +1 @@ +export const app = 'none'; diff --git a/test/comparison-tests/vueFileNotImportedWatch/patch1/app.ts b/test/comparison-tests/vueFileNotImportedWatch/patch1/app.ts new file mode 100644 index 000000000..eaecbc87d --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/patch1/app.ts @@ -0,0 +1,3 @@ +import component from './component.vue'; + +export const app = component.name; diff --git a/test/comparison-tests/vueFileNotImportedWatch/tsconfig.json b/test/comparison-tests/vueFileNotImportedWatch/tsconfig.json new file mode 100644 index 000000000..cf4cece4a --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "module": "commonjs", + "strict": true + }, + "include": [ + "*.ts" + ] +} diff --git a/test/comparison-tests/vueFileNotImportedWatch/webpack.config.js b/test/comparison-tests/vueFileNotImportedWatch/webpack.config.js new file mode 100644 index 000000000..0ae1920d3 --- /dev/null +++ b/test/comparison-tests/vueFileNotImportedWatch/webpack.config.js @@ -0,0 +1,28 @@ +// As vue-loader does, the script and the compiled template of component.vue +// both reach ts-loader, as requests for the same file. The script has a type +// error. +// - patch0: app.ts stops importing component.vue. TypeScript still has what +// ts-loader gave it for the script, which nothing keeps up to date now: its +// error is not reported, as a template's isn't. +// - patch1: app.ts imports it again. webpack brings the modules back from its +// cache without running the loaders, and the error is reported. +const options = { appendTsSuffixTo: [/\.vue$/] }; + +module.exports = { + mode: 'development', + entry: './app.ts', + output: { + filename: 'bundle.js' + }, + resolve: { + extensions: ['.ts', '.js'] + }, + module: { + rules: [ + { test: /\.ts$/, loader: 'ts-loader', options }, + { test: /\.vue$/, resourceQuery: /vue/, loader: 'ts-loader', options }, + { test: /\.vue$/, resourceQuery: /vue/, enforce: 'pre', loader: './block-loader.js' }, + { test: /\.vue$/, resourceQuery: { not: [/vue/] }, loader: './facade-loader.js' } + ] + } +}