datagrok-tools 4.8.0 → 4.8.1

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.
@@ -13,6 +13,8 @@ exports.checkImportStatements = checkImportStatements;
13
13
  exports.checkPackageFile = checkPackageFile;
14
14
  exports.extractExternals = extractExternals;
15
15
 
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+
16
18
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
19
 
18
20
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -99,17 +101,22 @@ function check(args) {
99
101
 
100
102
  var isWebpack = _fs["default"].existsSync(webpackConfigPath);
101
103
 
104
+ var externals = null;
105
+
102
106
  if (isWebpack) {
103
107
  var content = _fs["default"].readFileSync(webpackConfigPath, {
104
108
  encoding: 'utf-8'
105
109
  });
106
110
 
107
- var externals = extractExternals(content);
111
+ externals = extractExternals(content);
108
112
  if (externals) warnings.push.apply(warnings, (0, _toConsumableArray2["default"])(checkImportStatements(packagePath, jsTsFiles, externals)));
109
113
  }
110
114
 
111
115
  warnings.push.apply(warnings, (0, _toConsumableArray2["default"])(checkFuncSignatures(packagePath, funcFiles)));
112
- warnings.push.apply(warnings, (0, _toConsumableArray2["default"])(checkPackageFile(packagePath)));
116
+ warnings.push.apply(warnings, (0, _toConsumableArray2["default"])(checkPackageFile(packagePath, {
117
+ isWebpack: isWebpack,
118
+ externals: externals
119
+ })));
113
120
 
114
121
  if (warnings.length) {
115
122
  console.log("Checking package ".concat(_path["default"].basename(packagePath), "..."));
@@ -121,12 +128,12 @@ function check(args) {
121
128
  }
122
129
 
123
130
  function extractExternals(config) {
124
- var externalsRegex = /(?<=externals\s*:\s*)(\{[\S\s]*?\})/;
131
+ var externalsRegex = /(?<=externals)\s*:\s*(\{[\S\s]*?\})/;
125
132
  var match = config.match(externalsRegex);
126
133
 
127
134
  if (match) {
128
- // Replace single quotes and a trailing comma to make a string JSON-like
129
- var externalStr = match[1].replace(/'/g, '"').replace(/(?<=[\S\s]),(?=\s*\})/, '');
135
+ // Replace single quotes, comments, and a trailing comma to make a string JSON-like
136
+ var externalStr = match[1].replace(/'/g, '"').replace(/\/\/.*(\r\n|\r|\n)/, '').replace(/(?<=[\S\s]),(?=\s*\})/, '');
130
137
 
131
138
  try {
132
139
  var externals = JSON.parse(externalStr);
@@ -142,9 +149,9 @@ function extractExternals(config) {
142
149
  function checkImportStatements(packagePath, files, externals) {
143
150
  var modules = [];
144
151
 
145
- for (var key in externals) {
146
- modules.push(key);
147
- if (key.includes('/')) modules.push(key.split('/', 1)[0]);
152
+ for (var _key in externals) {
153
+ modules.push(_key);
154
+ if (_key.includes('/')) modules.push(_key.split('/', 1)[0]);
148
155
  }
149
156
 
150
157
  var importRegex = new RegExp("^(?!\\/{2})\\s*import\\s+.*(".concat(modules.join('|'), ").*(?=\\s+?)"), 'g');
@@ -402,7 +409,25 @@ function checkFuncSignatures(packagePath, files) {
402
409
  return warnings;
403
410
  }
404
411
 
405
- function checkPackageFile(packagePath) {
412
+ var sharedLibExternals = {
413
+ 'common/html2canvas.min.js': {
414
+ 'exceljs': 'ExcelJS'
415
+ },
416
+ 'common/exceljs.min.js': {
417
+ 'html2canvas': 'html2canvas'
418
+ },
419
+ 'common/ngl_viewer/ngl.js': {
420
+ 'NGL': 'NGL'
421
+ },
422
+ 'common/openchemlib-full.js': {
423
+ 'openchemlib/full': 'OCL'
424
+ },
425
+ 'common/codemirror/codemirror.js': {
426
+ 'codemirror': 'CodeMirror'
427
+ }
428
+ };
429
+
430
+ function checkPackageFile(packagePath, options) {
406
431
  var warnings = [];
407
432
 
408
433
  var packageFilePath = _path["default"].join(packagePath, 'package.json');
@@ -440,7 +465,30 @@ function checkPackageFile(packagePath) {
440
465
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
441
466
  var source = _step7.value;
442
467
  if (typeof source !== 'string') warnings.push("File \"package.json\": Only file paths and URLs are allowed in sources. Modify the source ".concat(source));
443
- if (source.startsWith('common/') || utils.absUrlRegex.test(source)) continue;
468
+ if (utils.absUrlRegex.test(source)) continue;
469
+
470
+ if (source.startsWith('common/')) {
471
+ if (options !== null && options !== void 0 && options.isWebpack && source.endsWith('.js')) {
472
+ if (options !== null && options !== void 0 && options.externals) {
473
+ if (source in sharedLibExternals) {
474
+ var _Object$entries$ = (0, _slicedToArray2["default"])(Object.entries(sharedLibExternals[source])[0], 2),
475
+ _lib = _Object$entries$[0],
476
+ name = _Object$entries$[1];
477
+
478
+ if (!(_lib in options.externals && options.externals[_lib] === name)) {
479
+ warnings.push("Webpack config parsing: Consider adding source \"".concat(source, "\" to webpack externals:\n") + "'".concat(_lib, "': '").concat(name, "'\n"));
480
+ }
481
+ } else {
482
+ warnings.push("File \"package.json\": source \"".concat(source, "\" not in the list of shared libraries"));
483
+ }
484
+ } else {
485
+ warnings.push('Webpack config parsing: External modules not found.\n' + "Consider adding source \"".concat(source, "\" to webpack externals") + (source in sharedLibExternals ? ':\n' + "'".concat(Object.keys(sharedLibExternals[source])[0], "': '").concat(Object.values(sharedLibExternals[source])[0], "'\n") : ''));
486
+ }
487
+ }
488
+
489
+ continue;
490
+ }
491
+
444
492
  if (source.startsWith('src/') && _fs["default"].existsSync(_path["default"].join(packagePath, 'webpack.config.js'))) warnings.push('File "package.json": Sources cannot include files from the \`src/\` directory. ' + "Move file ".concat(source, " to another folder."));
445
493
  if (!_fs["default"].existsSync(_path["default"].join(packagePath, source))) warnings.push("Source ".concat(source, " not found in the package."));
446
494
  }
@@ -121,16 +121,15 @@ function link(args) {
121
121
  var lib = _step2.value;
122
122
 
123
123
  if ("".concat(libScope, "/").concat(lib.name) in dependencies) {
124
- if (lib.isSymbolicLink()) {
125
- console.log("Package \"".concat(lib.name, "\" is linked. Skipping..."));
126
- } else {
127
- console.log("Linking \"".concat(lib.name, "\"..."));
128
- (0, _child_process.exec)('npm install && npm run build && npm link', {
129
- cwd: _path["default"].join(paths[libScope], lib.name)
130
- }, function (err, stdout, stderr) {
131
- if (err) throw err;else console.log(stderr, stdout);
132
- });
133
- }
124
+ var libPath = _path["default"].join(paths[libScope], lib.name);
125
+
126
+ var isLinked = lib.isSymbolicLink();
127
+ console.log(isLinked ? "Package \"".concat(lib.name, "\" is linked. Updating dependencies and running the build script...") : "Linking \"".concat(lib.name, "\"..."));
128
+ (0, _child_process.exec)(isLinked ? 'npm update && npm run build' : 'npm install && npm run build && npm link', {
129
+ cwd: libPath
130
+ }, function (err, stdout, stderr) {
131
+ if (err) throw err;else console.log(stderr, stdout);
132
+ });
134
133
  }
135
134
  }
136
135
  } catch (err) {
@@ -145,43 +144,38 @@ function link(args) {
145
144
  return m.name === 'utils';
146
145
  }), 1)[0];
147
146
 
148
- if (utilsModule.isSymbolicLink()) {
149
- console.log("Package \"".concat(utilsModule.name, "\" is linked. Skipping..."));
150
- } else {
151
- console.log("Linking \"".concat(utilsModule.name, "\"..."));
152
- (0, _child_process.exec)('npm install && npm run build && npm link', {
153
- cwd: _path["default"].join(paths[libScope], 'utils')
154
- }, function (err, stdout, stderr) {
155
- if (err) throw err;else {
156
- console.log(stderr, stdout);
157
- f();
158
- }
159
- });
160
- }
161
- } else {
162
- f();
163
- }
164
- }
147
+ var libPath = _path["default"].join(paths[libScope], 'utils');
165
148
 
166
- if (apiModule != null) {
167
- if (apiModule.isSymbolicLink()) {
168
- console.log("Package \"".concat(apiModule.name, "\" is linked. Skipping..."));
169
- installLibs(libs);
170
- } else {
171
- console.log("Linking \"".concat(apiModule.name, "\"..."));
172
- (0, _child_process.exec)("npm install && npm run build && npm link", {
173
- cwd: paths[apiPackageName]
149
+ var isLinked = utilsModule.isSymbolicLink();
150
+ console.log(isLinked ? "Package \"".concat(utilsModule.name, "\" is linked. Updating dependencies and running the build script...") : "Linking \"".concat(utilsModule.name, "\"..."));
151
+ (0, _child_process.exec)(isLinked ? 'npm update && npm run build' : 'npm install && npm run build && npm link', {
152
+ cwd: libPath
174
153
  }, function (err, stdout, stderr) {
175
154
  if (err) throw err;else {
176
155
  console.log(stderr, stdout);
177
- installLibs(libs);
178
- var packageNames = Object.keys(dependencies).join(' ');
179
- (0, _child_process.exec)("npm link ".concat(packageNames));
156
+ f();
180
157
  }
181
158
  });
159
+ } else {
160
+ f();
182
161
  }
183
162
  }
184
163
 
164
+ if (apiModule != null) {
165
+ var isLinked = apiModule.isSymbolicLink();
166
+ console.log(isLinked ? "Package \"".concat(apiModule.name, "\" is linked. Updating dependencies and running the build script...") : "Linking \"".concat(apiModule.name, "\"..."));
167
+ (0, _child_process.exec)(isLinked ? "npm update && npm run build" : "npm install && npm run build && npm link", {
168
+ cwd: paths[apiPackageName]
169
+ }, function (err, stdout, stderr) {
170
+ if (err) throw err;else {
171
+ console.log(stderr, stdout);
172
+ installLibs(libs);
173
+ var packageNames = Object.keys(dependencies).join(' ');
174
+ (0, _child_process.exec)("npm link ".concat(packageNames));
175
+ }
176
+ });
177
+ }
178
+
185
179
  return true;
186
180
  }
187
181
  /** Unlinks local packages and runs `npm i`. */
@@ -27,6 +27,7 @@ module.exports = {
27
27
  'dayjs': 'dayjs',
28
28
  'wu': 'wu',
29
29
  'exceljs': 'ExcelJS',
30
+ 'html2canvas': 'html2canvas',
30
31
  },
31
32
  output: {
32
33
  filename: '[name].js',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datagrok-tools",
3
- "version": "4.8.0",
3
+ "version": "4.8.1",
4
4
  "description": "Utility to upload and publish packages to Datagrok",
5
5
  "homepage": "https://github.com/datagrok-ai/public/tree/master/tools#readme",
6
6
  "dependencies": {