Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that JSON files are included in build module resolution (#905) #1101

Merged
merged 3 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 7 additions & 0 deletions src/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ export function initializeInstance(
}

function getScriptRegexp(instance: TSInstance) {
// If resolveJsonModules is set, we should accept json files
if (instance.configParseResult.options.resolveJsonModule) {
// if allowJs is set then we should accept js(x) files
return instance.configParseResult.options.allowJs === true
? /\.tsx?$|\.json$|\.jsx?$/i
: /\.tsx?$|\.json$/i;
}
// if allowJs is set then we should accept js(x) files
return instance.configParseResult.options.allowJs === true
? /\.tsx?$|\.jsx?$/i
Expand Down
3 changes: 3 additions & 0 deletions test/comparison-tests/resolveJsonModule/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as file from "./file.json";

console.log(file.foo);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Asset Size Chunks Chunk Names
bundle.js 1.12 KiB 0 main
Entrypoint main = bundle.js
[0] ./app.ts 232 bytes {0} [built] [failed] [2 errors]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

ERROR in tsconfig.json
[tsl] ERROR
 TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["ap.ts","file.json"]' and 'exclude' paths were '[]'.

ERROR in ./app.ts
Module build failed (from index.js):
Error: error while parsing tsconfig.json
at Object.loader (dist/index.js:19:18)

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Asset Size Chunks Chunk Names
bundle.js 1.12 KiB 0 main
Entrypoint main = bundle.js
[0] ./app.ts 232 bytes {0} [built] [failed] [2 errors]

WARNING in configuration
The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment.
You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/

ERROR in tsconfig.json
[tsl] ERROR
 TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["ap.ts","file.json"]' and 'exclude' paths were '[]'.

ERROR in ./app.ts
Module build failed (from index.js):
Error: error while parsing tsconfig.json
at Object.loader (dist/index.js:19:18)
3 changes: 3 additions & 0 deletions test/comparison-tests/resolveJsonModule/file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"foo": "bar"
}
7 changes: 7 additions & 0 deletions test/comparison-tests/resolveJsonModule/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"composite": true
},
"include": ["ap.ts", "file.json"]
}
12 changes: 12 additions & 0 deletions test/comparison-tests/resolveJsonModule/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
entry: './app.ts',
output: {
filename: 'bundle.js'
},
resolve: {
extensions: ['.ts', '.json']
},
module: {
rules: [{ test: /\.tsx?$/, loader: 'ts-loader' }]
}
};