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.0 to 6.0.0-alpha.1

dist/index.js.map

0

dist/index.d.ts

@@ -0,0 +0,0 @@ import { SFCTemplateCompileOptions } from '@vue/compiler-sfc';

@@ -0,8 +1,409 @@

'use strict';
'use strict'
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
if (process.env.NODE_ENV === 'production') {
module.exports = require('./rollup-plugin-vue.cjs.production.min.js')
} else {
module.exports = require('./rollup-plugin-vue.cjs.development.js')
var compilerSfc = require('@vue/compiler-sfc');
var createDebugger = _interopDefault(require('debug'));
var hash = _interopDefault(require('hash-sum'));
var path = require('path');
var qs = _interopDefault(require('querystring'));
var rollupPluginutils = require('rollup-pluginutils');
var sourcemapCodec = require('sourcemap-codec');
/*! *****************************************************************************
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 {
require.resolve('@vue/compiler-sfc');
}
catch (e) {
throw new Error('vue-loader requires @vue/compiler-sfc to be present in the dependency ' +
'tree.');
}
var debug = createDebugger('rollup-plugin-vue');
var defaultOptions = {
include: /\.vue$/,
exclude: [],
target: 'browser',
exposeFilename: false,
};
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);
return {
name: 'vue',
resolveId: function (id) {
var query = parseVuePartRequest(id);
if (query.vue) {
debug("resolveId(" + id + ")");
return id;
}
return undefined;
},
load: function (id) {
var query = parseVuePartRequest(id);
if (query.vue) {
var descriptor = getDescriptor(query.filename);
var block_1 = query.type === 'template'
? descriptor.template
: query.type === 'script'
? descriptor.script
: query.type === 'style'
? descriptor.styles[query.index]
: query.type === 'custom'
? descriptor.customBlocks[query.index]
: null;
if (block_1) {
var result = {
code: block_1.content,
map: normalizeSourceMap(block_1.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]);
}
return segments;
}));
}
debug("load(" + id + ")", '\n' +
result.code +
'\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,' +
Buffer.from(JSON.stringify(result.map), 'utf-8').toString('base64'));
return result;
}
}
return undefined;
},
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*/];
}
});
});
},
};
}
function parseVuePartRequest(id) {
var _a = id.split('?', 2), filename = _a[0], query = _a[1];
if (!query)
return { vue: false, filename: filename };
var 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 { vue: false, filename: filename };
}
var cache = new Map();
function getDescriptor(id) {
if (cache.has(id)) {
return cache.get(id);
}
throw new Error(id + " is not parsed it yet");
}
function parseSFC(code, id, sourceRoot) {
var _a = compilerSfc.parse(code, {
sourceMap: true,
filename: id,
sourceRoot: sourceRoot,
pad: 'line',
}), descriptor = _a.descriptor, errors = _a.errors;
cache.set(id, descriptor);
return { descriptor: descriptor, errors: errors };
}
function transformVueSFC(code, resourcePath, descriptor, _a, options) {
var rootContext = _a.rootContext, isProduction = _a.isProduction;
var shortFilePath = path.relative(rootContext, resourcePath)
.replace(/^(\.\.[\/\\])+/, '')
.replace(/\\/g, '/');
var 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 = [
scriptImport,
templateImport,
stylesCode,
"script.render = render",
];
if (hasScoped) {
output.push("script.__scopeId = " + _("data-v-" + id));
}
if (!isProduction) {
output.push("script.__file = " + _(shortFilePath));
}
else if (options.exposeFilename) {
output.push("script.__file = " + _(path.basename(shortFilePath)));
}
output.push('export default script');
return output.join('\n');
}
function getTemplateCode(descriptor, resourcePath, id, hasScoped) {
var templateImport = "const render = () => {}";
var 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;
templateRequest = _(src + query);
templateImport = "import { render } from " + templateRequest;
}
return templateImport;
}
function getScriptCode(descriptor, resourcePath) {
var 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);
scriptImport =
"import script from " + scriptRequest + "\n" + ("export * from " + scriptRequest); // support named exports
}
return scriptImport;
}
function getStyleCode(descriptor, resourcePath, id) {
var stylesCode = "";
var hasCSSModules = false;
if (descriptor.styles.length) {
descriptor.styles.forEach(function (style, i) {
var src = style.src || resourcePath;
var 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);
if (style.module) {
if (!hasCSSModules) {
stylesCode += "const cssModules = script.__cssModules = {}";
hasCSSModules = true;
}
stylesCode += genCSSModulesCode(id, i, styleRequest, style.module);
}
else {
stylesCode += "\nimport " + styleRequest;
}
// TODO SSR critical CSS collection
});
}
return stylesCode;
}
function createRollupError(id, error) {
return {
id: id,
plugin: 'vue',
pluginCode: String(error.code),
message: error.message,
frame: error.loc.source,
parserError: error,
loc: error.loc
? {
file: id,
line: error.loc.start.line,
column: error.loc.start.column,
}
: undefined,
};
}
// these are built-in query parameters so should be ignored
// if the user happen to add them as attrs
var 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)) : "");
}
}
if (langFallback && !("lang" in attrs)) {
query += "&lang." + langFallback;
}
return query;
}
function _(any) {
return JSON.stringify(any);
}
function normalizeSourceMap(map) {
if (!map)
return null;
return {
version: Number(map.version),
file: map.file,
names: map.names,
sources: map.sources,
sourceRoot: map.sourceRoot,
sourcesContent: map.sourcesContent,
mappings: typeof map.mappings === 'string' ? map.mappings : '',
};
}
function genCSSModulesCode(
// @ts-ignore
id, index, request, moduleName) {
var styleVar = "style" + index;
var code = "\nimport " + styleVar + " from " + request;
// inject variable
var name = typeof moduleName === 'string' ? moduleName : '$style';
code += "\ncssModules[\"" + name + "\"] = " + styleVar;
return code;
}
module.exports = PluginVue;
//# sourceMappingURL=index.js.map

24

package.json
{
"name": "rollup-plugin-vue",
"version": "6.0.0-alpha.0",
"version": "6.0.0-alpha.1",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/rollup-plugin-vue.esm.js",
"typings": "dist/index.d.ts",

@@ -15,2 +14,3 @@ "author": "Rahul Kadyan <hi@znck.me> (https://znck.me)",

"hash-sum": "^2.0.0",
"lint-staged": "^10.1.1",
"rollup-pluginutils": "^2.8.2",

@@ -23,5 +23,6 @@ "sourcemap-codec": "^1.4.8"

"devDependencies": {
"@vue/compiler-sfc": "^3.0.0-alpha.10",
"@rollup/plugin-typescript": "^4.0.0",
"@types/debug": "^4.1.5",
"@types/jest": "^24.9.0",
"@vue/compiler-sfc": "^3.0.0-alpha.10",
"husky": "^4.2.0",

@@ -34,4 +35,11 @@ "rollup": "^1.29.1",

"husky": {
"hooks": {}
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,js,json}": [
"prettier --write"
]
},
"prettier": {

@@ -44,8 +52,8 @@ "printWidth": 80,

"scripts": {
"build": "tsdx build",
"lint": "tsdx lint",
"prepare": "tsdx build",
"start": "tsdx watch",
"build": "rollup -c",
"lint": "tsdx lint src",
"prepublishOnly": "npm run build",
"start": "tsdx watch --target node",
"test": "tsdx test"
}
}
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