Socket
Socket
Sign inDemoInstall

rollup-plugin-vue

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-vue - npm Package Compare versions

Comparing version 6.0.0-alpha.1 to 6.0.0-alpha.2

411

dist/index.js

@@ -13,65 +13,2 @@ 'use strict';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
try {

@@ -84,4 +21,4 @@ require.resolve('@vue/compiler-sfc');

}
var debug = createDebugger('rollup-plugin-vue');
var defaultOptions = {
const debug = createDebugger('rollup-plugin-vue');
const defaultOptions = {
include: /\.vue$/,

@@ -92,15 +29,17 @@ exclude: [],

};
function PluginVue(userOptions) {
if (userOptions === void 0) { userOptions = {}; }
var options = __assign(__assign({}, defaultOptions), userOptions);
var isServer = options.target === 'node';
var isProduction = process.env.NODE_ENV === 'production' || process.env.BUILD === 'production';
var rootContext = process.cwd();
var filter = rollupPluginutils.createFilter(options.include, options.exclude);
function PluginVue(userOptions = {}) {
const options = {
...defaultOptions,
...userOptions,
};
const isServer = options.target === 'node';
const isProduction = process.env.NODE_ENV === 'production' || process.env.BUILD === 'production';
const rootContext = process.cwd();
const filter = rollupPluginutils.createFilter(options.include, options.exclude);
return {
name: 'vue',
resolveId: function (id) {
var query = parseVuePartRequest(id);
resolveId(id) {
const query = parseVuePartRequest(id);
if (query.vue) {
debug("resolveId(" + id + ")");
debug(`resolveId(${id})`);
return id;

@@ -110,7 +49,7 @@ }

},
load: function (id) {
var query = parseVuePartRequest(id);
load(id) {
const query = parseVuePartRequest(id);
if (query.vue) {
var descriptor = getDescriptor(query.filename);
var block_1 = query.type === 'template'
const descriptor = getDescriptor(query.filename);
const block = query.type === 'template'
? descriptor.template

@@ -124,13 +63,13 @@ : query.type === 'script'

: null;
if (block_1) {
var result = {
code: block_1.content,
map: normalizeSourceMap(block_1.map),
if (block) {
const result = {
code: block.content,
map: normalizeSourceMap(block.map),
};
if (query.type === 'template') {
// generate source mapping for each character.
result.map.mappings = sourcemapCodec.encode(result.code.split(/\r?\n/).map(function (line, index) {
var segments = [];
for (var i = 0; i < line.length; ++i) {
segments.push([i, 0, block_1.loc.start.line + index - 1, i]);
result.map.mappings = sourcemapCodec.encode(result.code.split(/\r?\n/).map((line, index) => {
const segments = [];
for (let i = 0; i < line.length; ++i) {
segments.push([i, 0, block.loc.start.line + index - 1, i]);
}

@@ -140,3 +79,3 @@ return segments;

}
debug("load(" + id + ")", '\n' +
debug(`load(${id})`, '\n' +
result.code +

@@ -150,94 +89,81 @@ '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +

},
transform: function (code, id) {
return __awaiter(this, void 0, void 0, function () {
var query, descriptor, block, result, block, result, _a, descriptor, errors, output;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
query = parseVuePartRequest(id);
if (!query.vue) return [3 /*break*/, 4];
descriptor = getDescriptor(query.filename);
if (!(query.type === 'template')) return [3 /*break*/, 1];
debug("transform(" + id + ")");
block = descriptor.template;
result = compilerSfc.compileTemplate({
filename: query.filename,
source: code,
preprocessLang: block.lang,
compiler: options.compiler,
compilerOptions: options.compilerOptions,
transformAssetUrls: options.transformAssetUrls,
});
if (result.errors.length) {
result.errors.forEach(function (error) {
return _this.error(typeof error === 'string'
? { id: query.filename, message: error }
: createRollupError(query.filename, error));
});
return [2 /*return*/, null];
}
if (result.tips.length) {
result.tips.forEach(function (tip) {
return _this.warn({
id: query.filename,
message: tip,
});
});
}
return [2 /*return*/, {
code: result.code,
map: normalizeSourceMap(result.map),
}];
case 1:
if (!(query.type === 'style' && query.scoped)) return [3 /*break*/, 3];
debug("transform(" + id + ")");
block = descriptor.styles[query.index];
return [4 /*yield*/, compilerSfc.compileStyleAsync({
filename: query.filename,
id: "data-v-" + query.id,
source: block.content,
scoped: query.scoped,
trim: true,
})];
case 2:
result = _b.sent();
if (result.errors.length) {
result.errors.forEach(function (error) {
return _this.error({
id: query.filename,
message: error.message,
});
});
return [2 /*return*/, null];
}
return [2 /*return*/, {
code: result.code,
map: normalizeSourceMap(result.map),
}];
case 3: return [2 /*return*/, null];
case 4:
if (filter(id)) {
debug("transform(" + id + ")");
_a = parseSFC(code, id, rootContext), descriptor = _a.descriptor, errors = _a.errors;
if (errors.length) {
errors.forEach(function (error) { return _this.error(createRollupError(id, error)); });
return [2 /*return*/, null];
}
output = transformVueSFC(code, id, descriptor, { rootContext: rootContext, isProduction: isProduction, isServer: isServer }, options);
debug('transient .vue file:', '\n' + output + '\n');
return [2 /*return*/, {
code: output,
map: {
mappings: '',
},
}];
}
else {
return [2 /*return*/, null];
}
case 5: return [2 /*return*/];
async transform(code, id) {
const query = parseVuePartRequest(id);
if (query.vue) {
const descriptor = getDescriptor(query.filename);
if (query.type === 'template') {
debug(`transform(${id})`);
const block = descriptor.template;
const result = compilerSfc.compileTemplate({
filename: query.filename,
source: code,
preprocessLang: block.lang,
compiler: options.compiler,
compilerOptions: {
...options.compilerOptions,
scopeId: `data-v-${query.id}`,
},
transformAssetUrls: options.transformAssetUrls,
});
if (result.errors.length) {
result.errors.forEach(error => this.error(typeof error === 'string'
? { id: query.filename, message: error }
: createRollupError(query.filename, error)));
return null;
}
});
});
if (result.tips.length) {
result.tips.forEach(tip => this.warn({
id: query.filename,
message: tip,
}));
}
return {
code: result.code,
map: normalizeSourceMap(result.map),
};
}
else if (query.type === 'style' && query.scoped) {
debug(`transform(${id})`);
const block = descriptor.styles[query.index];
const result = await compilerSfc.compileStyleAsync({
filename: query.filename,
id: `data-v-${query.id}`,
source: block.content,
scoped: query.scoped,
trim: true,
});
if (result.errors.length) {
result.errors.forEach(error => this.error({
id: query.filename,
message: error.message,
}));
return null;
}
return {
code: result.code,
map: normalizeSourceMap(result.map),
};
}
return null;
}
else if (filter(id)) {
debug(`transform(${id})`);
const { descriptor, errors } = parseSFC(code, id, rootContext);
if (errors.length) {
errors.forEach(error => this.error(createRollupError(id, error)));
return null;
}
// module id for scoped CSS & hot-reload
const output = transformVueSFC(code, id, descriptor, { rootContext, isProduction, isServer }, options);
debug('transient .vue file:', '\n' + output + '\n');
return {
code: output,
map: {
mappings: '',
},
};
}
else {
return null;
}
},

@@ -247,12 +173,20 @@ };

function parseVuePartRequest(id) {
var _a = id.split('?', 2), filename = _a[0], query = _a[1];
const [filename, query] = id.split('?', 2);
if (!query)
return { vue: false, filename: filename };
var raw = qs.parse(query);
return { vue: false, filename };
const raw = qs.parse(query);
if ('vue' in raw) {
return __assign(__assign({}, raw), { filename: filename, vue: true, type: raw.type, index: Number(raw.index), scoped: 'scoped' in raw, module: raw.module });
return {
...raw,
filename,
vue: true,
type: raw.type,
index: Number(raw.index),
scoped: 'scoped' in raw,
module: raw.module,
};
}
return { vue: false, filename: filename };
return { vue: false, filename };
}
var cache = new Map();
const cache = new Map();
function getDescriptor(id) {

@@ -262,6 +196,6 @@ if (cache.has(id)) {

}
throw new Error(id + " is not parsed it yet");
throw new Error(`${id} is not parsed it yet`);
}
function parseSFC(code, id, sourceRoot) {
var _a = compilerSfc.parse(code, {
const { descriptor, errors } = compilerSfc.parse(code, {
sourceMap: true,

@@ -271,31 +205,30 @@ filename: id,

pad: 'line',
}), descriptor = _a.descriptor, errors = _a.errors;
});
cache.set(id, descriptor);
return { descriptor: descriptor, errors: errors };
return { descriptor, errors };
}
function transformVueSFC(code, resourcePath, descriptor, _a, options) {
var rootContext = _a.rootContext, isProduction = _a.isProduction;
var shortFilePath = path.relative(rootContext, resourcePath)
function transformVueSFC(code, resourcePath, descriptor, { rootContext, isProduction, }, options) {
const shortFilePath = path.relative(rootContext, resourcePath)
.replace(/^(\.\.[\/\\])+/, '')
.replace(/\\/g, '/');
var id = hash(isProduction ? shortFilePath + '\n' + code : shortFilePath);
const id = hash(isProduction ? shortFilePath + '\n' + code : shortFilePath);
// feature information
var hasScoped = descriptor.styles.some(function (s) { return s.scoped; });
var templateImport = getTemplateCode(descriptor, resourcePath, id, hasScoped);
var scriptImport = getScriptCode(descriptor, resourcePath);
var stylesCode = getStyleCode(descriptor, resourcePath, id);
var output = [
const hasScoped = descriptor.styles.some(s => s.scoped);
const templateImport = getTemplateCode(descriptor, resourcePath, id, hasScoped);
const scriptImport = getScriptCode(descriptor, resourcePath);
const stylesCode = getStyleCode(descriptor, resourcePath, id);
const output = [
scriptImport,
templateImport,
stylesCode,
"script.render = render",
`script.render = render`,
];
if (hasScoped) {
output.push("script.__scopeId = " + _("data-v-" + id));
output.push(`script.__scopeId = ${_(`data-v-${id}`)}`);
}
if (!isProduction) {
output.push("script.__file = " + _(shortFilePath));
output.push(`script.__file = ${_(shortFilePath)}`);
}
else if (options.exposeFilename) {
output.push("script.__file = " + _(path.basename(shortFilePath)));
output.push(`script.__file = ${_(path.basename(shortFilePath))}`);
}

@@ -306,12 +239,12 @@ output.push('export default script');

function getTemplateCode(descriptor, resourcePath, id, hasScoped) {
var templateImport = "const render = () => {}";
var templateRequest;
let templateImport = `const render = () => {}`;
let templateRequest;
if (descriptor.template) {
var src = descriptor.template.src || resourcePath;
var idQuery = "&id=" + id;
var scopedQuery = hasScoped ? "&scoped=true" : "";
var attrsQuery = attrsToQuery(descriptor.template.attrs);
var query = "?vue&type=template" + idQuery + scopedQuery + attrsQuery;
const src = descriptor.template.src || resourcePath;
const idQuery = `&id=${id}`;
const scopedQuery = hasScoped ? `&scoped=true` : ``;
const attrsQuery = attrsToQuery(descriptor.template.attrs);
const query = `?vue&type=template${idQuery}${scopedQuery}${attrsQuery}`;
templateRequest = _(src + query);
templateImport = "import { render } from " + templateRequest;
templateImport = `import { render } from ${templateRequest}`;
}

@@ -321,10 +254,10 @@ return templateImport;

function getScriptCode(descriptor, resourcePath) {
var scriptImport = "const script = {}";
let scriptImport = `const script = {}`;
if (descriptor.script) {
var src = descriptor.script.src || resourcePath;
var attrsQuery = attrsToQuery(descriptor.script.attrs, 'js');
var query = "?vue&type=script" + attrsQuery;
var scriptRequest = _(src + query);
const src = descriptor.script.src || resourcePath;
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js');
const query = `?vue&type=script${attrsQuery}`;
const scriptRequest = _(src + query);
scriptImport =
"import script from " + scriptRequest + "\n" + ("export * from " + scriptRequest); // support named exports
`import script from ${scriptRequest}\n` + `export * from ${scriptRequest}`; // support named exports
}

@@ -334,16 +267,16 @@ return scriptImport;

function getStyleCode(descriptor, resourcePath, id) {
var stylesCode = "";
var hasCSSModules = false;
let stylesCode = ``;
let hasCSSModules = false;
if (descriptor.styles.length) {
descriptor.styles.forEach(function (style, i) {
var src = style.src || resourcePath;
var attrsQuery = attrsToQuery(style.attrs, 'css');
descriptor.styles.forEach((style, i) => {
const src = style.src || resourcePath;
const attrsQuery = attrsToQuery(style.attrs, 'css');
// make sure to only pass id when necessary so that we don't inject
// duplicate tags when multiple components import the same css file
var idQuery = style.scoped ? "&id=" + id : "";
var query = "?vue&type=style&index=" + i + idQuery + attrsQuery;
var styleRequest = _(src + query);
const idQuery = style.scoped ? `&id=${id}` : ``;
const query = `?vue&type=style&index=${i}${idQuery}${attrsQuery}`;
const styleRequest = _(src + query);
if (style.module) {
if (!hasCSSModules) {
stylesCode += "const cssModules = script.__cssModules = {}";
stylesCode += `const cssModules = script.__cssModules = {}`;
hasCSSModules = true;

@@ -354,3 +287,3 @@ }

else {
stylesCode += "\nimport " + styleRequest;
stylesCode += `\nimport ${styleRequest}`;
}

@@ -364,3 +297,3 @@ // TODO SSR critical CSS collection

return {
id: id,
id,
plugin: 'vue',

@@ -382,13 +315,13 @@ pluginCode: String(error.code),

// if the user happen to add them as attrs
var ignoreList = ['id', 'index', 'src', 'type'];
const ignoreList = ['id', 'index', 'src', 'type'];
function attrsToQuery(attrs, langFallback) {
var query = "";
for (var name_1 in attrs) {
var value = attrs[name_1];
if (!ignoreList.includes(name_1)) {
query += "&" + qs.escape(name_1) + "=" + (value ? qs.escape(String(value)) : "");
let query = ``;
for (const name in attrs) {
const value = attrs[name];
if (!ignoreList.includes(name)) {
query += `&${qs.escape(name)}=${value ? qs.escape(String(value)) : ``}`;
}
}
if (langFallback && !("lang" in attrs)) {
query += "&lang." + langFallback;
if (langFallback && !(`lang` in attrs)) {
query += `&lang.${langFallback}`;
}

@@ -416,7 +349,7 @@ return query;

id, index, request, moduleName) {
var styleVar = "style" + index;
var code = "\nimport " + styleVar + " from " + request;
const styleVar = `style${index}`;
let code = `\nimport ${styleVar} from ${request}`;
// inject variable
var name = typeof moduleName === 'string' ? moduleName : '$style';
code += "\ncssModules[\"" + name + "\"] = " + styleVar;
const name = typeof moduleName === 'string' ? moduleName : '$style';
code += `\ncssModules["${name}"] = ${styleVar}`;
return code;

@@ -423,0 +356,0 @@ }

{
"name": "rollup-plugin-vue",
"version": "6.0.0-alpha.1",
"version": "6.0.0-alpha.2",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc