diff --git a/package.json b/package.json index f4e5f9c..11acffa 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": { "babel-runtime": "^6.23.0", "html-webpack-include-assets-plugin": "0.0.5", - "read-pkg": "^2.0.0", + "read-pkg-up": "^2.0.0", "resolve-pkg": "^1.0.0" }, "peerDependencies": { diff --git a/src/index.js b/src/index.js index a7fc0d6..4ccf3b0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ import moduleToCdn from 'module-to-cdn'; -import {sync as readPkg} from 'read-pkg'; +import {sync as readPkgUp} from 'read-pkg-up'; import HtmlWebpackIncludeAssetsPlugin from 'html-webpack-include-assets-plugin'; import ExternalModule from 'webpack/lib/ExternalModule'; import resolvePkg from 'resolve-pkg'; @@ -70,7 +70,7 @@ export default class ModulesCdnWebpackPlugin { return false; } - const {version, peerDependencies} = readPkg(resolvePkg(modulePath, {cwd: contextPath})); + const {version, peerDependencies} = readPkgUp({cwd: resolvePkg(modulePath, {cwd: contextPath})}).pkg; const cdnConfig = moduleToCdn(modulePath, version, {env}); diff --git a/test/core.js b/test/core.js index 210d158..bce3f14 100644 --- a/test/core.js +++ b/test/core.js @@ -330,3 +330,30 @@ test.serial('verbose options to output which modules are loaded from CDN / which console.log = originalLog; }); + +test('require files without extension', async t => { + await cleanDir(path.resolve(__dirname, './fixtures/output/require-file')); + + const stats = await runWebpack({ + context: path.resolve(__dirname, './fixtures/app'), + + output: { + publicPath: '', + path: path.resolve(__dirname, './fixtures/output/require-file') + }, + + entry: { + app: './require-file.js' + }, + + plugins: [ + new ModulesCdnWebpackPlugin() + ] + }); + + const files = stats.compilation.chunks.reduce((files, x) => files.concat(x.files), []); + + t.is(files.length, 1); + t.true(includes(files, 'app.js')); + t.false(includes(files, 'https://unpkg.com/react@15.6.1/dist/react.js')); +}); diff --git a/test/fixtures/app/require-file.js b/test/fixtures/app/require-file.js new file mode 100644 index 0000000..79a3fd2 --- /dev/null +++ b/test/fixtures/app/require-file.js @@ -0,0 +1 @@ +import React from 'react/react';