Skip to content

Commit 9342047

Browse files
author
Franck Freiburger
committed
wip(core): createCJSModule is now an option (that defaults to defaultCreateCJSModule)
1 parent 8567a06 commit 9342047

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

src/createVue2SFCModule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
interopRequireDefault,
2626
transformJSCode,
2727
loadDeps,
28-
createCJSModule,
2928
loadModuleInternal,
3029
} from './tools'
3130

@@ -70,7 +69,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
7069

7170
const component = {};
7271

73-
const { delimiters, whitespace, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelParserPlugins = [], additionalBabelPlugins = {}, customBlockHandler, devMode = false } = options;
72+
const { delimiters, whitespace, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelParserPlugins = [], additionalBabelPlugins = {}, customBlockHandler, devMode = false, createCJSModule } = options;
7473

7574
const descriptor = sfc_parse({
7675
source,

src/createVue3SFCModule.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
interopRequireDefault,
2525
transformJSCode,
2626
loadDeps,
27-
createCJSModule,
2827
loadModuleInternal,
2928
} from './tools'
3029

@@ -68,7 +67,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
6867

6968
const component : { [key: string]: any } = {};
7069

71-
const { delimiters, whitespace, isCustomElement, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelParserPlugins = [], additionalBabelPlugins = {}, customBlockHandler, devMode = false } = options;
70+
const { delimiters, whitespace, isCustomElement, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelParserPlugins = [], additionalBabelPlugins = {}, customBlockHandler, devMode = false, createCJSModule } = options;
7271

7372
// vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
7473
const { descriptor, errors } = sfc_parse(source, {

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
} from 'path'
44

55
import {
6-
loadModuleInternal
6+
loadModuleInternal,
7+
defaultCreateCJSModule,
78
} from './tools'
89

910
import {
@@ -31,8 +32,6 @@ export const version : string = process.env.VERSION as string;
3132
export const vueVersion : string = process.env.VUE_VERSION as string;
3233

3334

34-
export { createCJSModule } from './tools'
35-
3635
/**
3736
* @internal
3837
*/
@@ -161,6 +160,7 @@ export async function loadModule(path : AbstractPath, options : Options = throwN
161160
addStyle = throwNotDefined('options.addStyle()'),
162161
pathResolve = defaultPathResolve,
163162
getResource = defaultGetResource,
163+
createCJSModule = defaultCreateCJSModule,
164164
} = options;
165165

166166
// moduleCache should be defined with Object.create(null). require('constructor') etc... should not be a default module
@@ -174,6 +174,8 @@ export async function loadModule(path : AbstractPath, options : Options = throwN
174174
pathResolve,
175175
//@ts-ignore: is specified more than once, so this usage will be overwritten.ts(2783)
176176
getResource,
177+
//@ts-ignore: is specified more than once, so this usage will be overwritten.ts(2783)
178+
createCJSModule,
177179
...options,
178180
};
179181

src/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export async function loadModuleInternal(pathCx : PathContext, options : Options
324324
* Create a cjs module
325325
* @internal
326326
*/
327-
export function createCJSModule(refPath : AbstractPath, source : string, options : Options) : Module {
327+
export function defaultCreateCJSModule(refPath : AbstractPath, source : string, options : Options) : Module {
328328

329329
const { moduleCache, pathResolve, getResource } = options;
330330

@@ -360,7 +360,7 @@ export function createCJSModule(refPath : AbstractPath, source : string, options
360360
*/
361361
export async function createJSModule(source : string, moduleSourceType : boolean, filename : AbstractPath, options : Options) : Promise<ModuleExport> {
362362

363-
const { compiledCache, additionalBabelParserPlugins, additionalBabelPlugins, log } = options;
363+
const { compiledCache, additionalBabelParserPlugins, additionalBabelPlugins, createCJSModule, log } = options;
364364

365365
const [depsList, transformedSource] =
366366
await withCache(

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ export type Options = {
373373
loadModule?(path : AbstractPath, options : Options) : Promise<ModuleExport | undefined>,
374374

375375

376+
/**
377+
*
378+
*/
379+
createCJSModule(refPath : AbstractPath, source : string, options : Options) : Module,
380+
381+
382+
376383
/**
377384
* Abstact path handling
378385
*

0 commit comments

Comments
 (0)