Skip to content

Commit 2f441b9

Browse files
chrisvfritzyyx990803
authored andcommitted
feat: set file basename to __file in production (#1368)
1 parent fe91c8b commit 2f441b9

File tree

3 files changed

+1583
-1846
lines changed

3 files changed

+1583
-1846
lines changed

Diff for: lib/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,15 @@ var component = normalizer(
170170
code += `\n` + genHotReloadCode(id, hasFunctional, templateRequest)
171171
}
172172

173-
// Expose filename. This is used by the devtools and vue runtime warnings.
174-
if (!isProduction) {
175-
code += `\ncomponent.options.__file = ${JSON.stringify(rawShortFilePath)}`
176-
}
173+
// Expose filename. This is used by the devtools and Vue runtime warnings.
174+
code += `\ncomponent.options.__file = ${
175+
isProduction
176+
// For security reasons, only expose the file's basename in production.
177+
? JSON.stringify(filename)
178+
// Expose the file's full path in development, so that it can be opened
179+
// from the devtools.
180+
: JSON.stringify(rawShortFilePath)
181+
}`
177182

178183
code += `\nexport default component.exports`
179184
// console.log(code)

Diff for: test/advanced.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test('inherit queries on files', done => {
4646
})
4747
})
4848

49-
test('expose filename', done => {
49+
test('expose file path as __file outside production', done => {
5050
mockBundleAndRun({
5151
entry: 'basic.vue'
5252
}, ({ module }) => {
@@ -55,6 +55,21 @@ test('expose filename', done => {
5555
})
5656
})
5757

58+
test('expose file basename as __file in production', done => {
59+
const origNodeEnv = process.env.NODE_ENV
60+
process.env.NODE_ENV = 'production'
61+
mockBundleAndRun(
62+
{
63+
entry: 'basic.vue'
64+
},
65+
({ module }) => {
66+
expect(module.__file).toBe('basic.vue')
67+
process.env.NODE_ENV = origNodeEnv
68+
done()
69+
}
70+
)
71+
})
72+
5873
test('source map', done => {
5974
bundle({
6075
entry: 'basic.vue',

0 commit comments

Comments
 (0)