@stylable/module-utils
Advanced tools
Comparing version 2.3.3-alpha.0 to 2.3.3-alpha.1
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var core_1 = require("@stylable/core"); | ||
var module_source_1 = require("./module-source"); | ||
function stylableModuleFactory(stylableOptions, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.runtimePath, runtimePath = _c === void 0 ? '@stylable/runtime' : _c, _d = _b.runtimeStylesheetId, runtimeStylesheetId = _d === void 0 ? 'module' : _d, _e = _b.injectCSS, injectCSS = _e === void 0 ? true : _e, _f = _b.renderableOnly, renderableOnly = _f === void 0 ? false : _f, legacyRuntime = _b.legacyRuntime, _g = _b.staticImports, staticImports = _g === void 0 ? [] : _g; | ||
var afterModule = ''; | ||
var stylable = core_1.Stylable.create(stylableOptions); | ||
const core_1 = require("@stylable/core"); | ||
const module_source_1 = require("./module-source"); | ||
function stylableModuleFactory(stylableOptions, { runtimePath = '@stylable/runtime', runtimeStylesheetId = 'module', injectCSS = true, renderableOnly = false, legacyRuntime, staticImports = [] } = {}) { | ||
let afterModule = ''; | ||
const stylable = core_1.Stylable.create(stylableOptions); | ||
if (legacyRuntime && runtimePath === '@stylable/runtime') { | ||
@@ -34,6 +13,7 @@ runtimePath = '@stylable/runtime/cjs/index-legacy'; | ||
return function stylableToModule(source, path) { | ||
var res = stylable.transform(source, path); | ||
return module_source_1.generateModuleSource(res, runtimeStylesheetId === 'module' ? 'module.id' : res.meta.namespace, __spread(staticImports.map(function (request) { return "import " + JSON.stringify(request); }), [ | ||
"const runtime = require(" + JSON.stringify(runtimePath) + ")" | ||
]), "runtime.$", "runtime.create", "runtime.createRenderable", injectCSS ? JSON.stringify(res.meta.outputAst.toString()) : '""', '-1', // ToDo: calc depth for node as well | ||
const res = stylable.transform(source, path); | ||
return module_source_1.generateModuleSource(res, runtimeStylesheetId === 'module' ? 'module.id' : res.meta.namespace, [ | ||
...staticImports.map(request => `import ${JSON.stringify(request)}`), | ||
`const runtime = require(${JSON.stringify(runtimePath)})` | ||
], `runtime.$`, `runtime.create`, `runtime.createRenderable`, injectCSS ? JSON.stringify(res.meta.outputAst.toString()) : '""', '-1', // ToDo: calc depth for node as well | ||
'module.exports', afterModule, renderableOnly); | ||
@@ -40,0 +20,0 @@ }; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function generateModuleSource(stylableResult, moduleId, beforeModule, renderer, createFunction, createRenderableFunction, css, depth, exportsArgument, afterModule, renderableOnly) { | ||
if (renderableOnly === void 0) { renderableOnly = false; } | ||
var exports = stylableResult.exports, meta = stylableResult.meta; | ||
var localsExports = JSON.stringify(exports); | ||
var namespace = JSON.stringify(meta.namespace); | ||
function generateModuleSource(stylableResult, moduleId, beforeModule, renderer, createFunction, createRenderableFunction, css, depth, exportsArgument, afterModule, renderableOnly = false) { | ||
const { exports, meta } = stylableResult; | ||
const localsExports = JSON.stringify(exports); | ||
const namespace = JSON.stringify(meta.namespace); | ||
if (renderableOnly) { | ||
return createRenderableFunction + "(" + css + ", " + depth + ", " + moduleId + ");"; | ||
return `${createRenderableFunction}(${css}, ${depth}, ${moduleId});`; | ||
} | ||
return "\n" + beforeModule.join('\n') + "\n" + exportsArgument + " = " + createFunction + "(\n " + namespace + ",\n " + localsExports + ",\n " + css + ",\n " + depth + ",\n " + moduleId + ",\n " + renderer + "\n);\n" + afterModule + "\n"; | ||
return ` | ||
${beforeModule.join('\n')} | ||
${exportsArgument} = ${createFunction}( | ||
${namespace}, | ||
${localsExports}, | ||
${css}, | ||
${depth}, | ||
${moduleId}, | ||
${renderer} | ||
); | ||
${afterModule} | ||
`; | ||
} | ||
exports.generateModuleSource = generateModuleSource; | ||
function createModuleSource(stylableResult, moduleFormat, includeCSSInJS, moduleId, renderableOnly, depth, staticRequests, runtimeRequest, afterModule) { | ||
if (moduleFormat === void 0) { moduleFormat = 'cjs'; } | ||
if (moduleId === void 0) { moduleId = JSON.stringify(stylableResult.meta.namespace); } | ||
if (renderableOnly === void 0) { renderableOnly = false; } | ||
if (depth === void 0) { depth = '-1'; } | ||
if (staticRequests === void 0) { staticRequests = []; } | ||
if (runtimeRequest === void 0) { runtimeRequest = '@stylable/runtime'; } | ||
if (afterModule === void 0) { afterModule = []; } | ||
function createModuleSource(stylableResult, moduleFormat = 'cjs', includeCSSInJS, moduleId = JSON.stringify(stylableResult.meta.namespace), renderableOnly = false, depth = '-1', staticRequests = [], runtimeRequest = '@stylable/runtime', afterModule = []) { | ||
// TODO: calc depth for node as well | ||
@@ -52,11 +35,13 @@ depth = typeof depth === 'number' ? depth.toString() : depth; | ||
case 'esm': | ||
var importKey = renderableOnly ? 'createRenderable' : 'create'; | ||
return generateModuleSource(stylableResult, moduleId, __spread(staticRequests.map(function (request) { return "import " + JSON.stringify(request); }), [ | ||
"import { $, " + importKey + " } from " + JSON.stringify(runtimeRequest) | ||
]), "$", "create", "createRenderable", includeCSSInJS ? JSON.stringify(stylableResult.meta.outputAst.toString()) : '""', depth, 'const { classes, keyframes, vars, stVars, cssStates, style, st, $depth, $id, $css }', // = $ | ||
__spread(["export { classes, keyframes, vars, stVars, cssStates, style, st, $depth, $id, $css };"], afterModule).join('\n'), renderableOnly); | ||
const importKey = renderableOnly ? 'createRenderable' : 'create'; | ||
return generateModuleSource(stylableResult, moduleId, [ | ||
...staticRequests.map(request => `import ${JSON.stringify(request)}`), | ||
`import { $, ${importKey} } from ${JSON.stringify(runtimeRequest)}` | ||
], `$`, `create`, `createRenderable`, includeCSSInJS ? JSON.stringify(stylableResult.meta.outputAst.toString()) : '""', depth, 'const { classes, keyframes, vars, stVars, cssStates, style, st, $depth, $id, $css }', // = $ | ||
[`export { classes, keyframes, vars, stVars, cssStates, style, st, $depth, $id, $css };`, ...afterModule].join('\n'), renderableOnly); | ||
case 'cjs': | ||
return generateModuleSource(stylableResult, moduleId, __spread(staticRequests.map(function (request) { return "require(" + JSON.stringify(request) + ")"; }), [ | ||
"const runtime = require(" + JSON.stringify(runtimeRequest) + ")" | ||
]), "runtime.$", "runtime.create", "runtime.createRenderable", includeCSSInJS ? JSON.stringify(stylableResult.meta.outputAst.toString()) : '""', depth, 'module.exports', afterModule.join('\n'), renderableOnly); | ||
return generateModuleSource(stylableResult, moduleId, [ | ||
...staticRequests.map(request => `require(${JSON.stringify(request)})`), | ||
`const runtime = require(${JSON.stringify(runtimeRequest)})` | ||
], `runtime.$`, `runtime.create`, `runtime.createRenderable`, includeCSSInJS ? JSON.stringify(stylableResult.meta.outputAst.toString()) : '""', depth, 'module.exports', afterModule.join('\n'), renderableOnly); | ||
} | ||
@@ -63,0 +48,0 @@ throw new Error('Unknown module format ' + moduleFormat); |
{ | ||
"name": "@stylable/module-utils", | ||
"version": "2.3.3-alpha.0", | ||
"version": "2.3.3-alpha.1", | ||
"description": "Stylable module creation utilities", | ||
@@ -14,3 +14,3 @@ "main": "cjs/index.js", | ||
"dependencies": { | ||
"@stylable/core": "^2.3.3-alpha.0" | ||
"@stylable/core": "^2.3.3-alpha.1" | ||
}, | ||
@@ -27,3 +27,3 @@ "files": [ | ||
"license": "BSD-3-Clause", | ||
"gitHead": "a8fb880ad95147f02bfe18631167e0e9d6abd942" | ||
"gitHead": "9dfdbda11e88cfd20459ec0e3fbdca24f2e2223b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18711
240