New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

polymer-bundler

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polymer-bundler - npm Package Compare versions

Comparing version 4.0.0-pre.6 to 4.0.0-pre.7

lib/test/import-meta-url_test.d.ts

8

CHANGELOG.md

@@ -8,5 +8,11 @@ # Change Log

<!-- ## Unreleased -->
<!--## Unreleased -->
<!-- Add new, unreleased changes here. -->
## 4.0.0-pre.7 - 2018-05-03
* Dropped support for node v6. This is a soft break, as we aren't
making any changes that are known to break node v6, but we're no longer testing against it. See our [node version support policy](https://www.polymer-project.org/2.0/docs/tools/node-support)
for details.
* Added support for `import.meta.url` preservation in bundled modules.
## 4.0.0-pre.6 - 2018-04-25

@@ -13,0 +19,0 @@ - Bundled documents now have a `language` field. It will be `html` when the ast

3

lib/bundle-manifest.js

@@ -16,2 +16,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const assert = require("assert");
const clone = require("clone");

@@ -78,3 +79,3 @@ const deps_index_1 = require("./deps-index");

for (const fileUrl of bundle.files) {
console.assert(!this._bundleUrlForFile.has(fileUrl));
assert(!this._bundleUrlForFile.has(fileUrl));
this._bundleUrlForFile.set(fileUrl, bundleUrl);

@@ -81,0 +82,0 @@ }

@@ -88,2 +88,3 @@ import { ResolvedUrl } from 'polymer-analyzer';

private _rewriteImportNamespaceSpecifier(specifier, source, sourceBundle);
private _rewriteImportMetaToBundleMeta(moduleFile, relativeUrl);
}

@@ -33,2 +33,3 @@ "use strict";

const utils_1 = require("./utils");
const acornImportMetaInject = require('acorn-import-meta/inject');
/**

@@ -66,3 +67,11 @@ * Utility class to rollup/merge ES6 modules code using rollup and rewrite

onwarn: (warning) => { },
experimentalDynamicImport: true,
treeshake: false,
acorn: {
plugins: {
dynamicImport: true,
importMeta: true,
},
},
acornInjectPlugins: [acornImportMetaInject],
plugins: [

@@ -87,5 +96,8 @@ {

load: (id) => {
// When requesting the main document, just return it as-is.
if (id === input) {
return code;
}
// When the requested document is part of the bundle, get it from
// the analysis.
if (this.bundle.bundle.files.has(id)) {

@@ -111,3 +123,21 @@ const document = analyzer_utils_1.getAnalysisDocument(analysis, id);

}
return document.parsedDocument.contents;
// If the URL of the requested document is the same as the bundle
// URL or the requested file doesn't use `import.meta` anywhere,
// we can return it as-is.
if (this.bundle.url === id ||
!document.parsedDocument.contents.includes('import.meta')) {
return document.parsedDocument.contents;
}
// We need to rewrite instances of `import.meta` in the document
// to preserve its location because `import.meta` is used and the
// URL has changed as a result of bundling.
const relativeUrl = url_utils_1.ensureLeadingDot(this.bundler.analyzer.urlResolver.relative(this.bundle.url, id));
// TODO(usergenic): This code makes assumptions about the type of
// the ast and the document contents that are potentially not true
// if there are coding or resolution errors. Need to add some kind
// of type checking or assertion that we're dealing with at least
// a `Document<ParsedJavascriptDocument>` here.
const newAst = this._rewriteImportMetaToBundleMeta(document.parsedDocument.ast, relativeUrl);
const newCode = babel_utils_1.serialize(newAst).code;
return newCode;
}

@@ -117,3 +147,2 @@ },

],
experimentalDynamicImport: true,
});

@@ -124,5 +153,5 @@ const { code: rolledUpCode } = yield rollupBundle.generate({

});
// We have to force the extension of the URL to analyze here because inline
// es6 module document url is going to end in `.html` and the file would be
// incorrectly analyzed as an HTML document.
// We have to force the extension of the URL to analyze here because
// inline es6 module document url is going to end in `.html` and the file
// would be incorrectly analyzed as an HTML document.
const rolledUpUrl = url_utils_1.getFileExtension(url) === '.js' ?

@@ -160,5 +189,2 @@ url :

const importDeclaration = path.node;
if (!babel.isImportDeclaration(importDeclaration)) {
return;
}
const source = babel.isStringLiteral(importDeclaration.source) &&

@@ -388,4 +414,44 @@ importDeclaration.source.value;

}
_rewriteImportMetaToBundleMeta(moduleFile, relativeUrl) {
// Generate a stand-in for any local references to import.meta...
// const __bundledImportMeta = {...import.meta, url: __bundledImportURL};
// TODO(usergenic): Consider migrating this AST production mishmash into the
// `ast` tagged template literal available like this:
// https://github.com/Polymer/tools/blob/master/packages/build/src/babel-plugin-dynamic-import-amd.ts#L64
const bundledImportMetaName = '__bundledImportMeta';
const bundledImportMetaDeclaration = babel.variableDeclaration(
//
'const', [
//
babel.variableDeclarator(babel.identifier(bundledImportMetaName), babel.objectExpression([
babel.spreadProperty(babel.memberExpression(babel.identifier('import'), babel.identifier('meta'))),
babel.objectProperty(babel.identifier('url'), babel.memberExpression(babel.newExpression(babel.identifier('URL'), [
//
babel.stringLiteral(relativeUrl),
babel.memberExpression(babel.memberExpression(babel.identifier('import'), babel.identifier('meta')), babel.identifier('url'))
]), babel.identifier('href')))
]))
]);
const newModuleFile = clone(moduleFile);
babel_traverse_1.default(newModuleFile, {
noScope: true,
MetaProperty: {
enter(path) {
const metaProperty = path.node;
if (metaProperty.meta.name !== 'import' &&
metaProperty.property.name !== 'meta') {
// We're specifically looking for instances of `import.meta` so
// ignore any other meta properties.
return;
}
const bundledImportMeta = babel.identifier(bundledImportMetaName);
path.replaceWith(bundledImportMeta);
},
},
});
newModuleFile.program.body.unshift(bundledImportMetaDeclaration);
return newModuleFile;
}
}
exports.Es6Rewriter = Es6Rewriter;
//# sourceMappingURL=es6-rewriter.js.map

@@ -45,3 +45,3 @@ "use strict";

let bundler;
beforeEach(() => {
setup(() => {
analyzer = undefined;

@@ -48,0 +48,0 @@ bundler = undefined;

@@ -117,3 +117,3 @@ "use strict";

let bundle;
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
setup(() => __awaiter(this, void 0, void 0, function* () {
bundler = new bundler_1.Bundler();

@@ -120,0 +120,0 @@ yield bundler.analyzeContents(mainDocUrl, '', true);

@@ -45,3 +45,3 @@ "use strict";

const entrypoint2 = resolve('shards/shop_style_project/entrypoint2.html');
beforeEach(() => {
setup(() => {
analyzer = undefined;

@@ -48,0 +48,0 @@ bundler = undefined;

{
"name": "polymer-bundler",
"version": "4.0.0-pre.6",
"version": "4.0.0-pre.7",
"description": "Process Web Components into one output file",
"homepage": "https://github.com/Polymer/tools/tree/master/packages/bundler",
"repository": {
"type": "git",
"url": "git://github.com/Polymer/polymer-bundler.git"
},
"bugs": {
"url": "https://github.com/Polymer/polymer-bundler/issues"
},
"license": "BSD-3-Clause",
"author": "The Polymer Project Authors",
"main": "lib/bundler.js",

@@ -19,4 +29,4 @@ "typings": "lib/bundler.d.ts",

"@types/babel-traverse": "^6.25.3",
"@types/node": "^9.6.4",
"@types/rollup": "^0.54.0",
"acorn-import-meta": "^0.2.1",
"babel-generator": "^6.26.1",

@@ -32,3 +42,3 @@ "babel-traverse": "^6.26.0",

"parse5": "^2.2.2",
"polymer-analyzer": "=3.0.0-pre.24",
"polymer-analyzer": "=3.0.0-pre.25",
"rollup": "^0.56.1",

@@ -43,3 +53,3 @@ "source-map": "^0.5.6",

"@types/mocha": "^2.2.29",
"@types/node": "^6.0.33",
"@types/node": "^8.10.11",
"@types/parse5": "^2.2.33",

@@ -61,9 +71,7 @@ "@types/source-map": "=0.5.2",

"build": "tsc",
"format": "find src | grep '\\.js$\\|\\.ts$' | xargs ./node_modules/.bin/clang-format --style=file -i",
"test": "npm run build && tslint -c tslint.json src/*.ts src/**/*.ts && mocha",
"test:unit": "mocha",
"test:watch": "tsc-then -- mocha"
"format": "find src | grep \"\\.js$\\|\\.ts$\" | xargs ./node_modules/.bin/clang-format --style=file -i",
"test": "npm run build && tslint -c tslint.json \"src/**/*.ts\" && mocha \"lib/test/**/*_test.js\"",
"test:unit": "mocha \"lib/test/**/*_test.js\"",
"test:watch": "tsc-then -- mocha \"lib/test/**/*_test.js\""
},
"author": "The Polymer Project Authors",
"license": "BSD-3-Clause",
"directories": {

@@ -75,10 +83,3 @@ "test": "test"

"polymer"
],
"repository": {
"type": "git",
"url": "git://github.com/Polymer/polymer-bundler.git"
},
"bugs": {
"url": "https://github.com/Polymer/polymer-bundler/issues"
}
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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