diff --git a/test/fixtures/javascript.js b/test/fixtures/javascript.js new file mode 100644 index 0000000..96613c1 --- /dev/null +++ b/test/fixtures/javascript.js @@ -0,0 +1 @@ +require('./secret_js.txt') diff --git a/test/fixtures/raw_js_mod.js b/test/fixtures/raw_js_mod.js new file mode 100644 index 0000000..f638930 --- /dev/null +++ b/test/fixtures/raw_js_mod.js @@ -0,0 +1,4 @@ +module.exports = function (src) { + this._module._jsSource = true + return src +} diff --git a/test/fixtures/secret_js.txt b/test/fixtures/secret_js.txt new file mode 100644 index 0000000..6b66ceb --- /dev/null +++ b/test/fixtures/secret_js.txt @@ -0,0 +1 @@ +{ look: 'this is actually valid js!' } diff --git a/test/index.js b/test/index.js index 905a45f..b580fe3 100644 --- a/test/index.js +++ b/test/index.js @@ -14,7 +14,7 @@ test.cb('basic text content works correctly', (t) => { resolveLoader: { alias: { source: path.join(__dirname, '../lib/index.js') } }, - module: { loaders: [{ test: /\.txt$/, loader: 'source' }] } + module: { rules: [{ test: /\.txt$/, loader: 'source' }] } }, (err, res) => { if (err) { t.fail(err) } t.truthy(res.compilation.errors.length < 1) @@ -33,7 +33,7 @@ test.cb('raw source is added to loader context', (t) => { resolveLoader: { alias: { source: path.join(__dirname, '../lib/index.js') } }, - module: { loaders: [{ test: /\.txt$/, loader: 'source' }] } + module: { rules: [{ test: /\.txt$/, loader: 'source' }] } }, (err, res) => { if (err) { t.fail(err) } const mod = res.compilation.modules.find((m) => { @@ -55,7 +55,7 @@ test.cb('binary files not exported but are made availble for plugins', (t) => { resolveLoader: { alias: { source: path.join(__dirname, '../lib/index.js') } }, - module: { loaders: [{ test: /\.gif$/, loader: 'source' }] } + module: { rules: [{ test: /\.gif$/, loader: 'source' }] } }, (err, res) => { if (err) { t.fail(err) } const src = fs.readFileSync(outputPath, 'utf8') @@ -64,3 +64,31 @@ test.cb('binary files not exported but are made availble for plugins', (t) => { t.end() }) }) + +test.cb('valid js source parsed by setting the _jsSource prop', (t) => { + const outputPath = path.join(fixturesPath, 'build-js.js') + webpack({ + context: fixturesPath, + entry: path.join(fixturesPath, 'javascript'), + output: { path: fixturesPath, filename: 'build-js.js' }, + resolveLoader: { + alias: { + source: path.join(__dirname, '../lib/index.js'), + rawJs: path.join(__dirname, './fixtures/raw_js_mod.js') + } + }, + module: { + rules: [{ + test: /\.txt$/, + use: [{ loader: 'source' }, { loader: 'rawJs' }] + }] + } + }, (err, res) => { + if (err) { t.fail(err) } + t.truthy(res.compilation.errors.length < 1) + const src = fs.readFileSync(outputPath, 'utf8') + t.regex(src, /module\.exports = { look: 'this is actually valid js!' }/) + fs.unlinkSync(outputPath) + t.end() + }) +}) diff --git a/yarn.lock b/yarn.lock index db58730..5c8703c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1075,8 +1075,8 @@ concordance@^3.0.0: well-known-symbols "^1.0.0" configstore@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.0.tgz#45df907073e26dfa1cf4b2d52f5b60545eaa11d1" + version "3.1.1" + resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.1.tgz#094ee662ab83fad9917678de114faaea8fcdca90" dependencies: dot-prop "^4.1.0" graceful-fs "^4.1.2" @@ -2479,7 +2479,7 @@ istanbul-lib-hook@^1.0.7: dependencies: append-transform "^0.4.0" -istanbul-lib-instrument@^1.7.3: +istanbul-lib-instrument@^1.7.4: version "1.7.4" resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.4.tgz#e9fd920e4767f3d19edc765e2d6b3f5ccbd0eea8" dependencies: @@ -2998,8 +2998,8 @@ number-is-nan@^1.0.0: resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" nyc@^11.0.3: - version "11.0.3" - resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.0.3.tgz#0c28bc669a851621709bf7a08503034bee3812b6" + version "11.1.0" + resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.1.0.tgz#d6b3c5e16892a25af63138ba484676aa8a22eda7" dependencies: archy "^1.0.0" arrify "^1.0.1" @@ -3013,7 +3013,7 @@ nyc@^11.0.3: glob "^7.0.6" istanbul-lib-coverage "^1.1.1" istanbul-lib-hook "^1.0.7" - istanbul-lib-instrument "^1.7.3" + istanbul-lib-instrument "^1.7.4" istanbul-lib-report "^1.1.1" istanbul-lib-source-maps "^1.2.1" istanbul-reports "^1.1.1" @@ -3024,7 +3024,7 @@ nyc@^11.0.3: resolve-from "^2.0.0" rimraf "^2.5.4" signal-exit "^3.0.1" - spawn-wrap "^1.3.7" + spawn-wrap "^1.3.8" test-exclude "^4.1.1" yargs "^8.0.1" yargs-parser "^5.0.0" @@ -3832,7 +3832,7 @@ source-map@^0.5.0, source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, sour version "0.5.6" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412" -spawn-wrap@^1.3.7: +spawn-wrap@^1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/spawn-wrap/-/spawn-wrap-1.3.8.tgz#fa2a79b990cbb0bb0018dca6748d88367b19ec31" dependencies: