mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
fix(storage): replace non-word characters with underscore (#542)
This commit is contained in:
parent
f4cf2199a5
commit
5394aef2f7
@ -1,6 +1,7 @@
|
||||
import { resolve } from 'upath'
|
||||
import globby from 'globby'
|
||||
import type { Plugin } from 'rollup'
|
||||
import { serializeImportName } from '../../utils'
|
||||
|
||||
const PLUGIN_NAME = 'dynamic-require'
|
||||
const HELPER_DYNAMIC = `\0${PLUGIN_NAME}.js`
|
||||
@ -63,7 +64,7 @@ export function dynamicRequire ({ dir, ignore, inline }: Options): Plugin {
|
||||
const chunks = files.map(id => ({
|
||||
id,
|
||||
src: resolve(dir, id).replace(/\\/g, '/'),
|
||||
name: '_' + id.replace(/[^a-zA-Z0-9_]/g, '_'),
|
||||
name: serializeImportName(id),
|
||||
meta: getWebpackChunkMeta(resolve(dir, id))
|
||||
})).filter(chunk => chunk.meta)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import virtual from '@rollup/plugin-virtual'
|
||||
import { serializeImportName } from '../../utils'
|
||||
|
||||
export interface StorageOptions {
|
||||
mounts: {
|
||||
@ -34,17 +35,13 @@ export function storage (opts: StorageOptions) {
|
||||
import { createStorage } from 'unstorage'
|
||||
import { assets } from '#assets'
|
||||
|
||||
${driverImports.map(i => `import ${getImportName(i)} from '${i}'`).join('\n')}
|
||||
${driverImports.map(i => `import ${serializeImportName(i)} from '${i}'`).join('\n')}
|
||||
|
||||
export const storage = createStorage({})
|
||||
|
||||
storage.mount('/assets', assets)
|
||||
|
||||
${mounts.map(m => `storage.mount('${m.path}', ${getImportName(m.driver)}(${JSON.stringify(m.opts)}))`).join('\n')}
|
||||
${mounts.map(m => `storage.mount('${m.path}', ${serializeImportName(m.driver)}(${JSON.stringify(m.opts)}))`).join('\n')}
|
||||
`
|
||||
})
|
||||
}
|
||||
|
||||
function getImportName (id: string) {
|
||||
return '_' + id.replace(/[\\/.]/g, '_')
|
||||
}
|
||||
|
@ -120,3 +120,8 @@ export function getDependencies (dir: string, mode: keyof typeof _getDependencie
|
||||
}
|
||||
return dependencies
|
||||
}
|
||||
|
||||
// TODO: Refactor to scule (https://github.com/unjs/scule/issues/6)
|
||||
export function serializeImportName (id: string) {
|
||||
return '_' + id.replace(/[^a-zA-Z0-9_$]/g, '_')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user