@oroinc/oro-webpack-config-builder 5.1.0-alpha44 → 5.1.0-alpha45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,8 @@
1
1
  const path = require('path');
2
- const _loaderUtils = require('loader-utils');
3
2
 
4
3
  module.exports = function(source) {
5
4
  this.cacheable && this.cacheable();
6
- const {resolver, relativeTo = ''} = _loaderUtils.getOptions(this) || {};
5
+ const {resolver, relativeTo = ''} = this.getOptions() || {};
7
6
 
8
7
  if (typeof resolver !== 'function') {
9
8
  return source;
@@ -1 +1,10 @@
1
- module.exports=function(e){var n={};function t(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}return t.m=e,t.c=n,t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},t.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t.w={},t(t.s=3)}([function(e,n){e.exports=require("babel-core")},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var i=t(0);n.default=(0,i.template)("\n module.exports = function __injector(__injections) {\n __injections = __injections || {};\n\n (function __validateInjection() {\n var validDependencies = DEPENDENCIES;\n var injectedDependencies = Object.keys(__injections);\n var invalidInjectedDependencies = injectedDependencies.filter(function (dependency) {\n return validDependencies.indexOf(dependency) === -1;\n });\n\n if (invalidInjectedDependencies.length > 0) {\n var validDependenciesString = ' - ' + validDependencies.join('\\n - ');\n var injectedDependenciesString = ' - ' + injectedDependencies.join('\\n - ');\n var invalidDependenciesString = ' - ' + invalidInjectedDependencies.join('\\n - ');\n\n throw new Error('Injection Error in ' + SOURCE_PATH + '\\n\\n' +\n 'The following injections are invalid:\\n' + invalidDependenciesString + '\\n\\n' +\n 'The following injections were passed in:\\n' + injectedDependenciesString + '\\n\\n' +\n 'Valid injection targets for this module are:\\n' + validDependenciesString + '\\n'\n );\n }\n })();\n\n __injector.sourcePath = SOURCE_PATH;\n __injector.validDependencies = DEPENDENCIES;\n\n var module = { exports: {} };\n var exports = module.exports;\n\n (function () {\n SOURCE\n })();\n\n return module.exports;\n }\n"),e.exports=n.default},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,n,t){var i=(0,r.transform)(n,{babelrc:!1,code:!1,compact:!1,filename:e.resourcePath}).ast,o=[];(0,r.traverse)(i,{CallExpression:function(e){r.types.isIdentifier(e.node.callee,{name:"require"})&&(o.push(function(e){var n=e.node.arguments[0].value;return e.replaceWith(r.types.expressionStatement(r.types.conditionalExpression(r.types.callExpression(r.types.memberExpression(r.types.identifier("__injections"),r.types.identifier("hasOwnProperty"),!1),[r.types.stringLiteral(n)]),r.types.memberExpression(r.types.identifier("__injections"),r.types.stringLiteral(n),!0),e.node))),n}(e)),e.skip())}}),0===o.length&&e.emitWarning("The module you are trying to inject into doesn't have any dependencies. Are you sure you want to do this?");var a=r.types.file(r.types.program([(0,s.default)({SOURCE:i,SOURCE_PATH:r.types.stringLiteral(e.resourcePath),DEPENDENCIES:r.types.arrayExpression(o.map(function(e){return r.types.stringLiteral(e)}))})]));return(0,r.transformFromAst)(a,n,{sourceMaps:e.sourceMap,sourceFileName:e.resourcePath,inputSourceMap:t,babelrc:!1,compact:!1,filename:e.resourcePath})};var i,r=t(0),o=t(1),s=(i=o)&&i.__esModule?i:{default:i};e.exports=n.default},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,n){this.cacheable&&this.cacheable();var t=(0,o.default)(this,e,n),i=t.code,r=t.map;this.callback(null,i,r)};var i,r=t(2),o=(i=r)&&i.__esModule?i:{default:i};e.exports=n.default}]);
1
+ const injectify = require('./injectify.js');
2
+
3
+ module.exports = function injectifyLoader(source, inputSourceMap) {
4
+ if (this.cacheable) {
5
+ this.cacheable();
6
+ }
7
+
8
+ const {code, map} = injectify(this, source, inputSourceMap);
9
+ this.callback(null, code, map);
10
+ }
@@ -0,0 +1,66 @@
1
+ const {transform, traverse, types: t, transformFromAst} = require('@babel/core');
2
+ const wrapperTemplate = require('./wrapper_template.js');
3
+
4
+ function processRequireCall(path) {
5
+ const dependencyString = path.node.arguments[0].value;
6
+ path.replaceWith(
7
+ t.expressionStatement(
8
+ t.conditionalExpression(
9
+ t.callExpression(
10
+ t.memberExpression(t.identifier('__injections'), t.identifier('hasOwnProperty'), false),
11
+ [t.stringLiteral(dependencyString)]
12
+ ),
13
+ t.memberExpression(t.identifier('__injections'), t.stringLiteral(dependencyString), true),
14
+ path.node
15
+ )
16
+ )
17
+ );
18
+
19
+ return dependencyString;
20
+ }
21
+
22
+ module.exports = function injectify(context, source, inputSourceMap) {
23
+ const {ast} = transform(source, {
24
+ babelrc: false,
25
+ code: false,
26
+ compact: false,
27
+ ast: true,
28
+ filename: context.resourcePath,
29
+ });
30
+
31
+ const dependencies = [];
32
+ traverse(ast, {
33
+ CallExpression(path) {
34
+ if (t.isIdentifier(path.node.callee, {name: 'require'})) {
35
+ dependencies.push(processRequireCall(path));
36
+ path.skip();
37
+ }
38
+ },
39
+ });
40
+
41
+ if (dependencies.length === 0) {
42
+ context.emitWarning(
43
+ "The module you are trying to inject into doesn't have any dependencies. " +
44
+ 'Are you sure you want to do this?'
45
+ );
46
+ }
47
+
48
+ const wrapperModuleAst = t.file(
49
+ t.program([
50
+ wrapperTemplate({
51
+ SOURCE: t.blockStatement(ast.program.body),
52
+ SOURCE_PATH: t.stringLiteral(context.resourcePath),
53
+ DEPENDENCIES: t.arrayExpression(dependencies.map(d => t.stringLiteral(d))),
54
+ }),
55
+ ])
56
+ );
57
+
58
+ return transformFromAst(wrapperModuleAst, source, {
59
+ sourceMaps: context.sourceMap,
60
+ sourceFileName: context.resourcePath,
61
+ inputSourceMap,
62
+ babelrc: false,
63
+ compact: false,
64
+ filename: context.resourcePath,
65
+ });
66
+ }
@@ -0,0 +1,32 @@
1
+ const {template} = require('@babel/core');
2
+
3
+ module.exports = template(`
4
+ module.exports = function __injector(__injections) {
5
+ __injections = __injections || {};
6
+ (function __validateInjection() {
7
+ var validDependencies = DEPENDENCIES;
8
+ var injectedDependencies = Object.keys(__injections);
9
+ var invalidInjectedDependencies = injectedDependencies.filter(function (dependency) {
10
+ return validDependencies.indexOf(dependency) === -1;
11
+ });
12
+ if (invalidInjectedDependencies.length > 0) {
13
+ var validDependenciesString = ' - ' + validDependencies.join('\\n - ');
14
+ var injectedDependenciesString = ' - ' + injectedDependencies.join('\\n - ');
15
+ var invalidDependenciesString = ' - ' + invalidInjectedDependencies.join('\\n - ');
16
+ throw new Error('Injection Error in ' + SOURCE_PATH + '\\n\\n' +
17
+ 'The following injections are invalid:\\n' + invalidDependenciesString + '\\n\\n' +
18
+ 'The following injections were passed in:\\n' + injectedDependenciesString + '\\n\\n' +
19
+ 'Valid injection targets for this module are:\\n' + validDependenciesString + '\\n'
20
+ );
21
+ }
22
+ })();
23
+ __injector.sourcePath = SOURCE_PATH;
24
+ __injector.validDependencies = DEPENDENCIES;
25
+ var module = { exports: {} };
26
+ var exports = module.exports;
27
+ (function () {
28
+ SOURCE
29
+ })();
30
+ return module.exports;
31
+ }
32
+ `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oroinc/oro-webpack-config-builder",
3
- "version": "5.1.0-alpha44",
3
+ "version": "5.1.0-alpha45",
4
4
  "author": "Oro, Inc (https://www.oroinc.com)",
5
5
  "license": "MIT",
6
6
  "description": "An integration of OroPlatform based applications with the Webpack.",
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["webpack:///webpack/bootstrap 393a9525777b8b817cc3","webpack:///external \"babel-core\"","webpack:///src/index.js","webpack:///src/injectify.js","webpack:///src/wrapper_template.js"],"sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 393a9525777b8b817cc3","module.exports = require(\"babel-core\");\n\n\n//////////////////\n// WEBPACK FOOTER\n// external \"babel-core\"\n// module id = 0\n// module chunks = 0","// @flow\n\nimport injectify from './injectify.js';\n\nexport default function injectifyLoader(source, inputSourceMap) {\n if (this.cacheable) {\n this.cacheable();\n }\n\n const { code, map } = injectify(this, source, inputSourceMap);\n this.callback(null, code, map);\n}\n\n\n\n// WEBPACK FOOTER //\n// src/index.js","// @flow\n\nimport { transform, traverse, types as t, transformFromAst } from 'babel-core';\nimport wrapperTemplate from './wrapper_template.js';\n\nfunction processRequireCall(path) {\n const dependencyString = path.node.arguments[0].value;\n path.replaceWith(\n t.expressionStatement(\n t.conditionalExpression(\n t.callExpression(\n t.memberExpression(\n t.identifier('__injections'),\n t.identifier('hasOwnProperty'),\n false,\n ),\n [\n t.stringLiteral(dependencyString),\n ],\n ),\n t.memberExpression(\n t.identifier('__injections'),\n t.stringLiteral(dependencyString),\n true,\n ),\n path.node,\n ),\n ),\n );\n\n return dependencyString;\n}\n\nexport default function injectify(context, source, inputSourceMap) {\n const { ast } = transform(source, {\n babelrc: false,\n code: false,\n compact: false,\n filename: context.resourcePath,\n });\n\n const dependencies = [];\n traverse(ast, {\n CallExpression(path) {\n if (t.isIdentifier(path.node.callee, { name: 'require' })) {\n dependencies.push(processRequireCall(path));\n path.skip();\n }\n },\n });\n\n if (dependencies.length === 0) {\n context.emitWarning('The module you are trying to inject into doesn\\'t have any dependencies. ' +\n 'Are you sure you want to do this?');\n }\n\n const dependenciesArrayAst = t.arrayExpression(\n dependencies.map(dependency => t.stringLiteral(dependency)),\n );\n const wrapperModuleAst = t.file(t.program([\n wrapperTemplate({ SOURCE: ast, DEPENDENCIES: dependenciesArrayAst }),\n ]));\n\n return transformFromAst(wrapperModuleAst, source, {\n sourceMaps: context.sourceMap,\n sourceFileName: context.resourcePath,\n inputSourceMap,\n babelrc: false,\n compact: false,\n filename: context.resourcePath,\n });\n}\n\n\n\n// WEBPACK FOOTER //\n// src/injectify.js","// @flow\n\nimport { template } from 'babel-core';\n\nexport default template(`\n module.exports = function __injector(__injections) {\n __injections = __injections || {};\n\n (function __validateInjection() {\n var validDependencies = DEPENDENCIES;\n var injectedDependencies = Object.keys(__injections);\n var invalidInjectedDependencies = injectedDependencies.filter(function (dependency) {\n return validDependencies.indexOf(dependency) === -1;\n });\n\n if (invalidInjectedDependencies.length > 0) {\n var validDependenciesString = '- ' + validDependencies.join('\\\\n- ');\n var injectedDependenciesString = '- ' + injectedDependencies.join('\\\\n- ');\n var invalidDependenciesString = '- ' + invalidInjectedDependencies.join('\\\\n- ');\n\n throw new Error('Some of the injections you passed in are invalid.\\\\n' +\n 'Valid injection targets for this module are:\\\\n' + validDependenciesString + '\\\\n' +\n 'The following injections were passed in:\\\\n' + injectedDependenciesString + '\\\\n' +\n 'The following injections are invalid:\\\\n' + invalidDependenciesString + '\\\\n'\n );\n }\n })();\n\n var module = { exports: {} };\n var exports = module.exports;\n\n (function () {\n SOURCE\n })();\n\n return module.exports;\n }\n`);\n\n\n\n// WEBPACK FOOTER //\n// src/wrapper_template.js"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;AC7DA;;;;;;;;;;;;;;;;;;;ACIA;AACA;AAHA;AACA;;;;;AACA;AACA;AACA;AACA;AACA;AAJA;AAAA;AAAA;AACA;AAKA;AACA;AACA;;;;;;;;;;;;;ACqBA;AACA;AAhCA;AACA;AAAA;AACA;;;;;AAJA;AACA;AAIA;AACA;AACA;AACA;AAsBA;AACA;AACA;AACA;AAAA;AAEA;AACA;AACA;AACA;AAJA;AADA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AANA;AACA;AAQA;AACA;AAEA;AACA;AACA;AACA;AAAA;AAEA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AANA;AAQA;;;;;;;;;;;;;;ACrEA;AACA;AACA;AACA;;;;A","sourceRoot":""}