Skip to content

Commit 73927bd

Browse files
author
Joel Denning
committed
Namespace module ids with package.json name. Resolves #1767.
1 parent 7402077 commit 73927bd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,18 @@ module.exports = function (source) {
9191

9292
const shortFilePath = rawShortFilePath.replace(/\\/g, '/') + resourceQuery
9393

94+
let moduleIdNamespace
95+
try {
96+
const packageJson = require(path.resolve(process.cwd(), 'package.json'))
97+
moduleIdNamespace = packageJson.name || ''
98+
} catch (err) {
99+
moduleIdNamespace = ''
100+
}
101+
94102
const id = hash(
95103
isProduction
96-
? (shortFilePath + '\n' + source.replace(/\r\n/g, '\n'))
97-
: shortFilePath
104+
? moduleIdNamespace + (shortFilePath + '\n' + source.replace(/\r\n/g, '\n'))
105+
: moduleIdNamespace + shortFilePath
98106
)
99107

100108
// feature information

test/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const baseConfig = {
4848
}
4949

5050
function genId (file) {
51-
return hash(path.join('test', 'fixtures', file).replace(/\\/g, '/'))
51+
const packageJson = require(path.resolve(process.cwd(), 'package.json'))
52+
const moduleIdNamespace = packageJson.name || ''
53+
return hash(moduleIdNamespace + path.join('test', 'fixtures', file).replace(/\\/g, '/'))
5254
}
5355

5456
function bundle (options, cb, wontThrowError) {

0 commit comments

Comments
 (0)