lincd-cli 0.2.41 → 0.2.43

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,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {value: true});
3
3
  /// <reference path="colors.d.ts" />
4
- const colors = require("colors");
4
+ const colors = require('colors');
5
5
  var exportRoot = '/lib';
6
6
  var libraryName = 'lincd';
7
7
  var lincdModules = new Map();
@@ -13,170 +13,174 @@ var includedLincdModules = new Set();
13
13
  //it basically turns every import from a lincd module into a lookup for that class/object in the global lincd object
14
14
  //See also: https://webpack.js.org/configuration/externals/
15
15
  var externaliseModules = function (config, es5) {
16
- function debug(...msgs) {
17
- msgs.unshift('externals: ');
18
- if (config && config.debug) {
19
- console.log.apply(null, msgs);
20
- }
16
+ function debug(...msgs) {
17
+ msgs.unshift('externals: ');
18
+ if (config && config.debug) {
19
+ console.log.apply(null, msgs);
21
20
  }
22
- function log(...msgs) {
23
- msgs.unshift('externals: ');
24
- console.log.apply(null, msgs);
21
+ }
22
+
23
+ function log(...msgs) {
24
+ msgs.unshift('externals: ');
25
+ console.log.apply(null, msgs);
26
+ }
27
+
28
+ // let externalKeys: string[] = config.externals ? Object.keys(config.externals) : [];
29
+ //return the function that is handed to webpack in the 'externals' option.
30
+ //it determines for each request what is external and what is not
31
+ return function ({context, request, contextInfo}, callback) {
32
+ // debug('checking '+request);
33
+ // debug('imported by '+contextInfo.issuer);
34
+ if (config.externals && config.externals[request]) {
35
+ if (!excludedExternals.has(request)) {
36
+ excludedExternals.add(request);
37
+ // debug(colors.magenta('Excluding request as defined in Gruntfile: ' + request));
38
+ debug(colors.red(request) + ' is defined as external --> excluded');
39
+ }
40
+ // return callback(config.externals[request]);
41
+ return callback(null, 'var ' + config.externals[request]);
25
42
  }
26
- // let externalKeys: string[] = config.externals ? Object.keys(config.externals) : [];
27
- //return the function that is handed to webpack in the 'externals' option.
28
- //it determines for each request what is external and what is not
29
- return function ({ context, request, contextInfo }, callback) {
30
- // debug('checking '+request);
31
- // debug('imported by '+contextInfo.issuer);
32
- if (config.externals && config.externals[request]) {
33
- if (!excludedExternals.has(request)) {
34
- excludedExternals.add(request);
35
- // debug(colors.magenta('Excluding request as defined in Gruntfile: ' + request));
36
- debug(colors.red(request) + ' is defined as external --> excluded');
37
- }
38
- // return callback(config.externals[request]);
39
- return callback(null, 'var ' + config.externals[request]);
40
- }
41
- //solution to a problem that turned out not to need a solution.
42
- // But if sub requests of externalized modules go wrong at some point, use this!
43
- /*let rootRequest = request.substring(0, request.indexOf('/'));
44
- if (externalKeys.indexOf(rootRequest) !== -1) {
45
- let key = rootRequest;
46
- let rest = request.substring(key.length).replace(/\//g, '.');
47
- // return callback(config.externals[request]);
48
- debug(
49
- colors.magenta(
50
- 'Excluding sub request as defined in Gruntfile: ' +
51
- request +
52
- ' -> ' +
53
- config.externals[key] +
54
- rest,
55
- ),
56
- );
57
- return callback(null, 'var ' + config.externals[request] + rest);
58
- }*/
59
- //log(colors.gray(request));
60
- //"@dacore/core/foo" => "daCore.core.foo"
61
- // if (/^\@dacore\//.test(request)) {
62
- //remove @dacore/
63
- // if (request.indexOf('@dacore') !== 0) {
64
- // console.warn(
65
- // colors.red('this plugin currently works with @dacore modules only'),
66
- // );
67
- // return;
68
- // }
69
- // debug(colors.green('request: ' + request));
70
- if (request.substr(0, 1) == '.' || request.substr(0, 1) == '/') {
71
- // debug('skipping local');
72
- callback();
73
- return;
74
- }
75
- if (request.indexOf('lincd/') === 0 && es5) {
76
- // var result = request.replace("@dacore/core/","@dacore/core-es5/");
77
- // debug('Requested ES6 for ES5 target: '+colors.yellow(request) + ' => ' + colors.cyan(result));
78
- debug('Requested ES6 for ES5 target: ' + colors.yellow(request));
79
- // return callback(null, 'commonjs '+result);
80
- }
81
- //get module name without @dacore
82
- // var transformed = request.substr(8);
83
- //find @scope and the next part between 2 slashes after
84
- //so @dacore/some-mod/lib/file.js
85
- // --> match[0] = @dacore/some-mod
86
- // --> match[1] = @dacore
87
- // --> match[2] = some-mod
88
- let [packageName, scope, cleanPackageName] = request.match(/(@[\w\-]+\/)?([\w\-]+)/);
89
- //if this module is listed as internal module in the config (or if we internalize all modules with '*')
90
- if (config && config.internals && (config.internals.indexOf(packageName) !== -1 || config.internals === '*')) {
91
- //then don't exclude and don't continue this function
92
- //only log once
93
- if (!includedInternals.has(packageName)) {
94
- includedInternals.add(packageName);
95
- debug(colors.blue(request) + ' marked internal --> included');
96
- }
97
- return callback();
98
- }
99
- //check if this module is a lincd module
100
- let isLincd = isLincdModule(debug, packageName);
101
- if (isLincd) {
102
- if (!includedLincdModules.has(packageName)) {
103
- includedLincdModules.add(packageName);
104
- debug(colors.magenta(packageName +
105
- ' is a lincd module, imports will be excluded from this bundle and refer to a global variable instead'));
106
- }
107
- }
108
- else {
109
- //avoid duplicate messages
110
- if (!excluded.has(packageName)) {
111
- excluded.add(packageName);
112
- debug(colors.green(packageName) + ' --> included');
113
- }
114
- return callback();
115
- }
116
- //remove export root path (for example with lincd/lib/models: the module has lib/ as root, so to get to the exported path lincd.models we need to remove it)
117
- let cleanRequest = request.replace(exportRoot, '');
118
- let targetVariable;
119
- //expects a flat export / global tree with all the modules classes
120
- //replace - by _ and remove es5, because both es6 and es5 modules will be listed under the bare module name in the global treemap
121
- let firstSlash = cleanRequest.indexOf('/');
122
- //if importing {x} from "lincd" (so directly from library without any paths)
123
- if (firstSlash === -1 && cleanRequest == libraryName) {
124
- //then we refer straight to the global object
125
- targetVariable = libraryName;
126
- }
127
- else {
128
- //for all other cases, there is slash, so lets split module before the first slash and classname after the last slash
129
- // let module = cleanRequest
130
- // .substr(0, firstSlash)
131
- // .replace(/-/g, '_')
132
- // .replace('_es5', '');
133
- if (packageName == libraryName) {
134
- //the library itself should directly expose the main class of each file for clean variable names
135
- targetVariable = libraryName;
136
- //targetVariable = libraryName + '.' + className;
137
- }
138
- else {
139
- //reading this back I'm not sure why module would be empty?
140
- //Note: we don't include className here anymore, since all linked Components/Utils register themselves as libraryName._modules.moduleName.ComponentName
141
- //and we don't do default exports, so the import would be `import {ComponentName} from 'foo'` OR `import {ComponentName} from 'foo/lib/components/ComponentName'`
142
- //Typescript then translates `ComponentName` to `ComponentName_1.ComponentName` in the javascript output
143
- //And when we build the tree, we put each individual exports of linked components directly under `lincd._modules.moduleName`
144
- //so here we return the entire module as the result of such imports
145
- //and ComponentName_1 will contain all things linked/exported by the module
146
- //and ComponentName_1.ComponentName resolves to the desired class/function
147
- targetVariable = libraryName + "._modules['" + packageName.replace(/\-/g, '_') + "']";
148
- //import {PersonView} from 'lincd-test/lib/PersonView';
149
- //lincd._modules.lincd_test
150
- //PersonView_1
151
- //PersonView_1.PersonView --> lincd._modules.lincd_test.PersonView
152
- // targetVariable =
153
- // libraryName +
154
- // '.' +
155
- // (module ? '_modules.' + module + '.' : '') +
156
- // className;
157
- }
158
- }
159
- debug(colors.yellow(request) + ' => ' + colors.cyan(targetVariable));
160
- //See also: https://webpack.js.org/configuration/externals/
161
- return callback(null, 'var ' + targetVariable);
162
- // }
163
- };
43
+ //solution to a problem that turned out not to need a solution.
44
+ // But if sub requests of externalized modules go wrong at some point, use this!
45
+ /*let rootRequest = request.substring(0, request.indexOf('/'));
46
+ if (externalKeys.indexOf(rootRequest) !== -1) {
47
+ let key = rootRequest;
48
+ let rest = request.substring(key.length).replace(/\//g, '.');
49
+ // return callback(config.externals[request]);
50
+ debug(
51
+ colors.magenta(
52
+ 'Excluding sub request as defined in Gruntfile: ' +
53
+ request +
54
+ ' -> ' +
55
+ config.externals[key] +
56
+ rest,
57
+ ),
58
+ );
59
+ return callback(null, 'var ' + config.externals[request] + rest);
60
+ }*/
61
+ //log(colors.gray(request));
62
+ //"@dacore/core/foo" => "daCore.core.foo"
63
+ // if (/^\@dacore\//.test(request)) {
64
+ //remove @dacore/
65
+ // if (request.indexOf('@dacore') !== 0) {
66
+ // console.warn(
67
+ // colors.red('this plugin currently works with @dacore modules only'),
68
+ // );
69
+ // return;
70
+ // }
71
+ // debug(colors.green('request: ' + request));
72
+ if (request.substr(0, 1) == '.' || request.substr(0, 1) == '/') {
73
+ // debug('skipping local');
74
+ callback();
75
+ return;
76
+ }
77
+ if (request.indexOf('lincd/') === 0 && es5) {
78
+ // var result = request.replace("@dacore/core/","@dacore/core-es5/");
79
+ // debug('Requested ES6 for ES5 target: '+colors.yellow(request) + ' => ' + colors.cyan(result));
80
+ debug('Requested ES6 for ES5 target: ' + colors.yellow(request));
81
+ // return callback(null, 'commonjs '+result);
82
+ }
83
+ //get module name without @dacore
84
+ // var transformed = request.substr(8);
85
+ //find @scope and the next part between 2 slashes after
86
+ //so @dacore/some-mod/lib/file.js
87
+ // --> match[0] = @dacore/some-mod
88
+ // --> match[1] = @dacore
89
+ // --> match[2] = some-mod
90
+ let [packageName, scope, cleanPackageName] = request.match(/(@[\w\-]+\/)?([\w\-]+)/);
91
+ //if this module is listed as internal module in the config (or if we internalize all modules with '*')
92
+ if (config && config.internals && (config.internals.indexOf(packageName) !== -1 || config.internals === '*')) {
93
+ //then don't exclude and don't continue this function
94
+ //only log once
95
+ if (!includedInternals.has(packageName)) {
96
+ includedInternals.add(packageName);
97
+ debug(colors.blue(request) + ' marked internal --> included');
98
+ }
99
+ return callback();
100
+ }
101
+ //check if this module is a lincd module
102
+ let isLincd = isLincdModule(debug, packageName);
103
+ if (isLincd) {
104
+ if (!includedLincdModules.has(packageName)) {
105
+ includedLincdModules.add(packageName);
106
+ debug(
107
+ colors.magenta(
108
+ packageName +
109
+ ' is a lincd module, imports will be excluded from this bundle and refer to a global variable instead',
110
+ ),
111
+ );
112
+ }
113
+ } else {
114
+ //avoid duplicate messages
115
+ if (!excluded.has(packageName)) {
116
+ excluded.add(packageName);
117
+ debug(colors.green(packageName) + ' --> included');
118
+ }
119
+ return callback();
120
+ }
121
+ //remove export root path (for example with lincd/lib/models: the module has lib/ as root, so to get to the exported path lincd.models we need to remove it)
122
+ let cleanRequest = request.replace(exportRoot, '');
123
+ let targetVariable;
124
+ //expects a flat export / global tree with all the modules classes
125
+ //replace - by _ and remove es5, because both es6 and es5 modules will be listed under the bare module name in the global treemap
126
+ let firstSlash = cleanRequest.indexOf('/');
127
+ //if importing {x} from "lincd" (so directly from library without any paths)
128
+ if (firstSlash === -1 && cleanRequest == libraryName) {
129
+ //then we refer straight to the global object
130
+ targetVariable = libraryName;
131
+ } else {
132
+ //for all other cases, there is slash, so lets split module before the first slash and classname after the last slash
133
+ // let module = cleanRequest
134
+ // .substr(0, firstSlash)
135
+ // .replace(/-/g, '_')
136
+ // .replace('_es5', '');
137
+ if (packageName == libraryName) {
138
+ //the library itself should directly expose the main class of each file for clean variable names
139
+ targetVariable = libraryName;
140
+ //targetVariable = libraryName + '.' + className;
141
+ } else {
142
+ //reading this back I'm not sure why module would be empty?
143
+ //Note: we don't include className here anymore, since all linked Components/Utils register themselves as libraryName._modules.moduleName.ComponentName
144
+ //and we don't do default exports, so the import would be `import {ComponentName} from 'foo'` OR `import {ComponentName} from 'foo/lib/components/ComponentName'`
145
+ //Typescript then translates `ComponentName` to `ComponentName_1.ComponentName` in the javascript output
146
+ //And when we build the tree, we put each individual exports of linked components directly under `lincd._modules.moduleName`
147
+ //so here we return the entire module as the result of such imports
148
+ //and ComponentName_1 will contain all things linked/exported by the module
149
+ //and ComponentName_1.ComponentName resolves to the desired class/function
150
+ targetVariable = libraryName + "._modules['" + packageName.replace(/\-/g, '_') + "']";
151
+ //import {PersonView} from 'lincd-test/lib/PersonView';
152
+ //lincd._modules.lincd_test
153
+ //PersonView_1
154
+ //PersonView_1.PersonView --> lincd._modules.lincd_test.PersonView
155
+ // targetVariable =
156
+ // libraryName +
157
+ // '.' +
158
+ // (module ? '_modules.' + module + '.' : '') +
159
+ // className;
160
+ }
161
+ }
162
+ debug(colors.yellow(request) + ' => ' + colors.cyan(targetVariable));
163
+ //See also: https://webpack.js.org/configuration/externals/
164
+ return callback(null, 'var ' + targetVariable);
165
+ // }
166
+ };
164
167
  };
168
+
165
169
  function isLincdModule(debug, packageName) {
166
- if (!lincdModules.has(packageName)) {
167
- // debug(colors.green('checking ' + moduleName + '/package.json'));
168
- let isLincdModule;
169
- let modulePackage;
170
- try {
171
- modulePackage = require(packageName + '/package.json');
172
- }
173
- catch (e) {
174
- debug(colors.red(packageName + '/package.json' + ' does not exist'));
175
- // return callback();
176
- }
177
- isLincdModule = modulePackage && modulePackage.lincd && true;
178
- lincdModules.set(packageName, isLincdModule);
170
+ if (!lincdModules.has(packageName)) {
171
+ // debug(colors.green('checking ' + moduleName + '/package.json'));
172
+ let isLincdModule;
173
+ let modulePackage;
174
+ try {
175
+ modulePackage = require(packageName + '/package.json');
176
+ } catch (e) {
177
+ debug(colors.red(packageName + '/package.json' + ' does not exist'));
178
+ // return callback();
179
179
  }
180
- return lincdModules.get(packageName);
180
+ isLincdModule = modulePackage && modulePackage.lincd && true;
181
+ lincdModules.set(packageName, isLincdModule);
182
+ }
183
+ return lincdModules.get(packageName);
181
184
  }
185
+
182
186
  exports.default = externaliseModules;
@@ -4,22 +4,24 @@
4
4
  * triggered webpack re-compilation/re-build
5
5
  */
6
6
  'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
7
+ Object.defineProperty(exports, '__esModule', {value: true});
8
+
8
9
  class WatchRunPlugin {
9
- apply(compiler) {
10
- compiler.hooks.watchRun.tap('WatchRun', (comp) => {
11
- const changedTimes = comp.watchFileSystem.watcher.mtimes;
12
- const changedFiles = Object.keys(changedTimes)
13
- .map((file) => `\n ${file}`)
14
- .join('');
15
- if (changedFiles.length) {
16
- console.log('====================================');
17
- console.log('NEW BUILD FILES CHANGED:', changedFiles);
18
- console.log('====================================');
19
- }
20
- });
21
- }
10
+ apply(compiler) {
11
+ compiler.hooks.watchRun.tap('WatchRun', (comp) => {
12
+ const changedTimes = comp.watchFileSystem.watcher.mtimes;
13
+ const changedFiles = Object.keys(changedTimes)
14
+ .map((file) => `\n ${file}`)
15
+ .join('');
16
+ if (changedFiles.length) {
17
+ console.log('====================================');
18
+ console.log('NEW BUILD FILES CHANGED:', changedFiles);
19
+ console.log('====================================');
20
+ }
21
+ });
22
+ }
22
23
  }
24
+
23
25
  /*class WebpackWatchRunPlugin {
24
26
  constructor(options?) {
25
27
  if (typeof options !== "object") options = {};