jspm 2.0.0-beta.6 → 3.0.0

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.
Files changed (100) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +20 -26
  3. package/dist/cli.js +1391 -0
  4. package/jspm.js +10 -0
  5. package/package.json +23 -50
  6. package/CHANGELOG.md +0 -21
  7. package/bin/jspm +0 -46
  8. package/lib/api.d.ts +0 -10
  9. package/lib/api.js +0 -71
  10. package/lib/api.js.map +0 -1
  11. package/lib/build/index.d.ts +0 -24
  12. package/lib/build/index.js +0 -163
  13. package/lib/build/index.js.map +0 -1
  14. package/lib/cli.d.ts +0 -1
  15. package/lib/cli.js +0 -701
  16. package/lib/cli.js.map +0 -1
  17. package/lib/compile/cjs-convert.d.ts +0 -7
  18. package/lib/compile/cjs-convert.js +0 -375
  19. package/lib/compile/cjs-convert.js.map +0 -1
  20. package/lib/compile/dew-resolve.d.ts +0 -9
  21. package/lib/compile/dew-resolve.js +0 -117
  22. package/lib/compile/dew-resolve.js.map +0 -1
  23. package/lib/compile/dew-worker.d.ts +0 -1
  24. package/lib/compile/dew-worker.js +0 -302
  25. package/lib/compile/dew-worker.js.map +0 -1
  26. package/lib/config/config-file.d.ts +0 -67
  27. package/lib/config/config-file.js +0 -591
  28. package/lib/config/config-file.js.map +0 -1
  29. package/lib/config/global-config-file.d.ts +0 -8
  30. package/lib/config/global-config-file.js +0 -89
  31. package/lib/config/global-config-file.js.map +0 -1
  32. package/lib/config/index.d.ts +0 -15
  33. package/lib/config/index.js +0 -59
  34. package/lib/config/index.js.map +0 -1
  35. package/lib/config/jspm-file.d.ts +0 -8
  36. package/lib/config/jspm-file.js +0 -84
  37. package/lib/config/jspm-file.js.map +0 -1
  38. package/lib/config/package-json-file.d.ts +0 -49
  39. package/lib/config/package-json-file.js +0 -332
  40. package/lib/config/package-json-file.js.map +0 -1
  41. package/lib/exec/index.d.ts +0 -12
  42. package/lib/exec/index.js +0 -117
  43. package/lib/exec/index.js.map +0 -1
  44. package/lib/install/bin.d.ts +0 -2
  45. package/lib/install/bin.js +0 -86
  46. package/lib/install/bin.js.map +0 -1
  47. package/lib/install/binary-build.d.ts +0 -2
  48. package/lib/install/binary-build.js +0 -89
  49. package/lib/install/binary-build.js.map +0 -1
  50. package/lib/install/fetch.d.ts +0 -53
  51. package/lib/install/fetch.js +0 -270
  52. package/lib/install/fetch.js.map +0 -1
  53. package/lib/install/index.d.ts +0 -66
  54. package/lib/install/index.js +0 -1164
  55. package/lib/install/index.js.map +0 -1
  56. package/lib/install/package.d.ts +0 -142
  57. package/lib/install/package.js +0 -625
  58. package/lib/install/package.js.map +0 -1
  59. package/lib/install/publish.d.ts +0 -14
  60. package/lib/install/publish.js +0 -186
  61. package/lib/install/publish.js.map +0 -1
  62. package/lib/install/registry-manager.d.ts +0 -134
  63. package/lib/install/registry-manager.js +0 -521
  64. package/lib/install/registry-manager.js.map +0 -1
  65. package/lib/install/source.d.ts +0 -10
  66. package/lib/install/source.js +0 -378
  67. package/lib/install/source.js.map +0 -1
  68. package/lib/map/common.d.ts +0 -13
  69. package/lib/map/common.js +0 -180
  70. package/lib/map/common.js.map +0 -1
  71. package/lib/map/esm-lexer.d.ts +0 -17
  72. package/lib/map/esm-lexer.js +0 -506
  73. package/lib/map/esm-lexer.js.map +0 -1
  74. package/lib/map/index.d.ts +0 -15
  75. package/lib/map/index.js +0 -356
  76. package/lib/map/index.js.map +0 -1
  77. package/lib/map/utils.d.ts +0 -10
  78. package/lib/map/utils.js +0 -181
  79. package/lib/map/utils.js.map +0 -1
  80. package/lib/overrides.d.ts +0 -3
  81. package/lib/overrides.js +0 -29
  82. package/lib/overrides.js.map +0 -1
  83. package/lib/project.d.ts +0 -71
  84. package/lib/project.js +0 -434
  85. package/lib/project.js.map +0 -1
  86. package/lib/utils/cache.d.ts +0 -11
  87. package/lib/utils/cache.js +0 -121
  88. package/lib/utils/cache.js.map +0 -1
  89. package/lib/utils/common.d.ts +0 -55
  90. package/lib/utils/common.js +0 -267
  91. package/lib/utils/common.js.map +0 -1
  92. package/lib/utils/opts.d.ts +0 -6
  93. package/lib/utils/opts.js +0 -200
  94. package/lib/utils/opts.js.map +0 -1
  95. package/lib/utils/run-cmd.d.ts +0 -4
  96. package/lib/utils/run-cmd.js +0 -39
  97. package/lib/utils/run-cmd.js.map +0 -1
  98. package/lib/utils/ui.d.ts +0 -38
  99. package/lib/utils/ui.js +0 -496
  100. package/lib/utils/ui.js.map +0 -1
package/lib/cli.js DELETED
@@ -1,701 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2014-2019 Guy Bedford (http://guybedford.com)
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const ui = require("./utils/ui");
19
- const fs = require("fs");
20
- const path = require("path");
21
- const process = require("process");
22
- const api = require("./api");
23
- const common_1 = require("./utils/common");
24
- const global_config_file_1 = require("./config/global-config-file");
25
- const package_1 = require("./install/package");
26
- const opts_1 = require("./utils/opts");
27
- const api_1 = require("./api");
28
- const utils_1 = require("./map/utils");
29
- const config_file_1 = require("./config/config-file");
30
- const publish_1 = require("./install/publish");
31
- const bin_1 = require("./install/bin");
32
- const child_process_1 = require("child_process");
33
- const installEqualRegEx = /^([@\-_\.a-z\d\/]+)=/i;
34
- function readTargetEquals(installArg) {
35
- let name, target;
36
- const match = installArg.match(installEqualRegEx);
37
- if (match) {
38
- name = match[1];
39
- target = installArg.substr(name.length + 1);
40
- }
41
- else {
42
- target = installArg;
43
- }
44
- return { name, target };
45
- }
46
- async function cliHandler(projectPath, cmd, args) {
47
- if (typeof args === 'string')
48
- args = args.split(' ');
49
- let setProjectPath = false;
50
- let project;
51
- try {
52
- let userInput = true, offline = false, preferOffline = false;
53
- // first read global options
54
- for (let i = 0; i < args.length; i++) {
55
- const arg = args[i];
56
- switch (arg) {
57
- case '-y':
58
- case '--skip-prompts':
59
- args.splice(i--, 1);
60
- ui.setUseDefaults(true);
61
- userInput = false;
62
- break;
63
- case '-l':
64
- case '--log':
65
- const logLevelString = args[i + 1];
66
- const logLevel = ui.LogType[logLevelString];
67
- if (typeof logLevel !== 'number') {
68
- ui.warn(`${common_1.bold(logLevelString)} is not a valid log level.`);
69
- return process.exit(1);
70
- }
71
- ui.setLogLevel(logLevel);
72
- args.splice(i, 2);
73
- i -= 2;
74
- break;
75
- case '-g':
76
- setProjectPath = true;
77
- projectPath = api.JSPM_GLOBAL_PATH;
78
- args.splice(i, 1);
79
- break;
80
- case '-p':
81
- case '--project':
82
- setProjectPath = true;
83
- projectPath = args[i + 1];
84
- args.splice(i, 2);
85
- i -= 2;
86
- break;
87
- case '-q':
88
- case '--prefer-offline':
89
- preferOffline = true;
90
- args.splice(i--, 1);
91
- break;
92
- case '--offline':
93
- offline = true;
94
- args.splice(i--, 1);
95
- break;
96
- }
97
- }
98
- if (process.env.JSPM_OFFLINE) {
99
- offline = true;
100
- }
101
- if (process.env.JSPM_PREFER_OFFLINE) {
102
- preferOffline = true;
103
- }
104
- if (process.env.JSPM_PROJECT) {
105
- setProjectPath = true;
106
- projectPath = process.env.JSPM_PROJECT;
107
- }
108
- if (process.env.JSPM_LOG) {
109
- const logLevelString = process.env.JSPM_LOG;
110
- const logLevel = ui.LogType[logLevelString];
111
- if (typeof logLevel === 'number')
112
- ui.setLogLevel(logLevel);
113
- }
114
- if (process.env.JSPM_SKIP_PROMPTS && process.env.JSPM_SKIP_PROMPTS !== '0' && process.env.JSPM_SKIP_PROMPTS !== 'false') {
115
- ui.setUseDefaults(true);
116
- userInput = true;
117
- }
118
- switch (cmd) {
119
- case undefined:
120
- case '-v':
121
- case '--version':
122
- case 'version':
123
- case 'v':
124
- // run project checks
125
- new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
126
- console.log(api.version + '\n' +
127
- (process.env.globalJspm === 'true' || process.env.localJspm === 'false'
128
- ? 'Running against global jspm install.'
129
- : 'Running against local jspm install.'));
130
- break;
131
- case 'h':
132
- case 'help':
133
- console.log(`${ /*bold('Init')}
134
- jspm init <path>? Initialize or validate a jspm project in the current directory
135
-
136
- ${*/common_1.bold('📦 Install')}
137
- jspm install [<registry>:]<pkg>[@<version>]
138
- jspm install git:<path> | git+https:<path> | https:<path> | file:<path>
139
- jspm install
140
- --edge Install to latest unstable resolution
141
- --lock Do not update any existing installs
142
- --latest Resolve all packages to latest versions
143
- --dev|peer|optional Install a dev, peer or optional dependency
144
- --override (-o) main=x.js Provide a package.json property override
145
-
146
- jspm update [<name>+] Update packages within package.json ranges
147
- jspm uninstall <name>+ Uninstall a top-level package
148
- jspm clean Clear unused dependencies
149
- jspm link [<name>] <source> Link a custom source as a named package
150
- jspm unlink [<name>] Reinstall a package to its registry target
151
- jspm checkout <name>+ Copy a package in jspm_packages to modify
152
-
153
- ${common_1.bold('🔥 Execute')}
154
- jspm <file> Execute a module with jspm module resolution
155
- jspm run <name> Run package.json "scripts"
156
- jspm bin <name> [-g] Run an installed bin script
157
- --cmd Output the bin script command w/o executing
158
- --path [-g] Output the bin path
159
-
160
- ${common_1.bold('🏭 Build')}
161
- jspm build <entry>+ [-d <outdir>] [-o <buildmap.json>]
162
- --format commonjs|system|amd Set the output module format for the build
163
- --external <name>|<map.json> Define build external boundary and aliases
164
- --hash-entries Use hash file names for the entry points
165
- --exclude-deps Treat project dependencies as externals
166
- --clear-dir Clear the output directory before building
167
- --source-map Output source maps
168
- --banner <file>|<source> Provide a banner for the build files
169
- --watch Watch build files for rebuild on change
170
- ${ /*jspm inspect (TODO) Inspect the installation constraints of a given dependency */''}
171
- ${common_1.bold('🔎 Inspect')}
172
- jspm resolve <module> [<parent>] Resolve a module name with the jspm resolver
173
- --browser|bin Resolve a module name in a conditional env
174
- --relative Output the path relative to the current cwd
175
- jspm trace <module>+ Trace a module graph
176
- jspm trace --deps <module>+ Trace the dependencies of modules
177
- ${ /*jspm trace --format graph|text|csv|json (TODO) Different output formats for trace*/''}
178
- ${common_1.bold('🔗 Import Maps')}
179
- jspm map -o importmap.json Generates an import map for all dependencies
180
- jspm map <module>+ Generate a import map for specific modules
181
- --flat-scope Flatten scopes for Chrome compatibility
182
- --map-base Output absolute paths relative to map base
183
- --production Use production resolutions
184
- --cdn Generate a import map against the jspm CDN
185
-
186
- ${common_1.bold('🚢 Publish')}
187
- jspm publish [<path>] [--otp <otp>] [--tag <tag>] [--public]
188
-
189
- ${common_1.bold('🔧 Configure')}
190
- jspm registry-config <name> Run configuration prompts for a registry
191
- jspm config <option> <setting> Set jspm global config
192
- jspm config --get <option> Get a jspm global config value
193
-
194
- ${common_1.bold('Command Flags')}
195
- --offline Run command offline using the jspm cache
196
- --prefer-offline (-q) Use cached lookups for fastest install
197
- --skip-prompts (-y) Use default options w/o user input
198
- --log ok|warn|err|debug|none Set the log level
199
- --project (-p) <path> Set the jspm project directory
200
- `);
201
- break;
202
- case 'init':
203
- throw new common_1.JspmUserError(`${common_1.bold('jspm init')} has not yet been implemented.`);
204
- /*const [generator, target = generator] = args[0] && args[0].split('=') || [undefined];
205
- const initPath = args[1] || '.';
206
- if (!generator) {
207
- throw new JspmUserError(`jspm init requires a provided ${bold('generator')} name.`);
208
- }
209
- const generatorName = `jspm-init-${generator}`;
210
- const exitCode = await api.run(target || generatorName, [initPath, ...args.slice(2)], { latest: true, userInput, offline });
211
- process.exit(exitCode);*/
212
- case 'r':
213
- case 'run':
214
- {
215
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
216
- const exitCode = await project.run(args[0], args.slice(1));
217
- process.exit(exitCode);
218
- }
219
- break;
220
- case 'b':
221
- case 'bin':
222
- {
223
- let options;
224
- if (args[0] === '--path' || args[0] === '--cmd' || args[0] === '-pc' || args[0] === '-cp') {
225
- ({ options } = opts_1.readOptions([args[0]], ['path', 'cmd']));
226
- args = args.slice(1);
227
- }
228
- else {
229
- options = {};
230
- }
231
- const binPath = path.join(projectPath, 'jspm_packages', '.bin');
232
- if (options.path) {
233
- if (args.length)
234
- throw new common_1.JspmUserError(`${common_1.bold('jspm bin --path')} doesn't take any arguments.`);
235
- // jspm bin --path -> log bin path
236
- console.log(binPath);
237
- }
238
- else {
239
- if (args.length === 0) {
240
- // jspm bin --cmd -> show Node exec command
241
- if (options.cmd) {
242
- console.log(bin_1.getBin());
243
- }
244
- // jspm bin -> Node zero arguments form
245
- else {
246
- const exitCode = await api.exec([]);
247
- process.exit(exitCode);
248
- }
249
- }
250
- else {
251
- let execPath = path.join(binPath, args[0]);
252
- if (common_1.isWindows)
253
- execPath += '.cmd';
254
- // jspm bin --cmd x -> display exec path
255
- if (options.cmd) {
256
- if (args.length > 1)
257
- throw new common_1.JspmUserError(`${common_1.bold('jspm bin --cmd')} only supports a single script name.`);
258
- console.log(execPath);
259
- }
260
- // jspm bin x -> run exec path
261
- else {
262
- const ps = child_process_1.spawn(execPath, args.slice(1), { stdio: 'inherit' });
263
- const exitCode = await new Promise((resolve, reject) => {
264
- ps.on('exit', code => resolve(code));
265
- ps.on('error', err => reject(err));
266
- });
267
- process.exit(exitCode);
268
- }
269
- }
270
- }
271
- }
272
- break;
273
- case 'publish':
274
- {
275
- let options;
276
- ({ args, options } = opts_1.readOptions(args, ['public'], ['otp', 'tag']));
277
- if (args.length > 1)
278
- throw new common_1.JspmUserError('Publish only takes one path argument.');
279
- projectPath = projectPath || args[0] && path.resolve(args[0]) || process.cwd();
280
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
281
- await publish_1.default(project, options);
282
- }
283
- break;
284
- /* case 'e':
285
- case 'exec': {
286
- const exitCode = await api.run(args);
287
- process.exit(exitCode);
288
- }
289
- break;*/
290
- case 't':
291
- case 'trace':
292
- {
293
- let options;
294
- ({ args, options } = opts_1.readOptions(args, ['react-native', 'production', 'electron', 'node', 'deps', 'exclude-deps'], ['out']));
295
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
296
- // NB: local map should be included in this in the exclude case still
297
- const map = (options.excludeDeps || options.deps) ? {} : await api.map(project, options);
298
- if (!args.length)
299
- throw new common_1.JspmUserError('Trace requires a list of module names to trace.');
300
- const traced = await api.trace(project, map, process.cwd(), args, options.excludeDeps || options.deps);
301
- if (options.deps) {
302
- const deps = new Set();
303
- for (const map of Object.values(traced)) {
304
- for (const dep of Object.keys(map)) {
305
- if (map[dep] in traced === false && !common_1.isURL(dep) && !dep.startsWith('./') && !dep.startsWith('../'))
306
- deps.add(dep);
307
- }
308
- }
309
- for (const dep of deps)
310
- console.log(dep);
311
- return;
312
- }
313
- const output = await config_file_1.serializeJson(traced, config_file_1.defaultStyle);
314
- if (options.out)
315
- await new Promise((resolve, reject) => fs.writeFile(options.out, output, err => err ? reject(err) : resolve()));
316
- else
317
- process.stdout.write(output);
318
- }
319
- break;
320
- case 'm':
321
- case 'map':
322
- {
323
- let options;
324
- ({ args, options } = opts_1.readOptions(args, ['react-native', 'production', 'electron', 'cdn', 'flat-scope', 'node'], ['out', 'in', 'jspmPackages', 'map-base']));
325
- if (options.node)
326
- throw new common_1.JspmUserError(`${common_1.bold('jspm map')} currently only supports generating package maps for the browser.`);
327
- let inputMap, style = config_file_1.defaultStyle;
328
- if (options.in)
329
- ({ json: inputMap, style } = await config_file_1.readJSONStyled(options.in));
330
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
331
- let map = await api.map(project, options);
332
- if (inputMap)
333
- map = utils_1.extend(utils_1.extend({}, inputMap), map);
334
- if (args.length)
335
- map = await api.filterMap(project, map, args, options.flatScope);
336
- else if (options.flatScope)
337
- utils_1.flattenScopes(map);
338
- if (options.cdn && !options.jspmPackages)
339
- options.jspmPackages = options.production ? 'https://cdn.jspm.io' : 'https://dev-cdn.jspm.io';
340
- const jspmPackagesURL = options.jspmPackages ? options.jspmPackages : options.out ? path.relative(path.dirname(path.resolve(options.out)), path.resolve(projectPath, 'jspm_packages')).replace(/\\/g, '/') : 'jspm_packages';
341
- if (jspmPackagesURL !== 'jspm_packages')
342
- map = api.renormalizeMap(map, jspmPackagesURL, options.cdn);
343
- // we dont want input map items filtered so always add them back
344
- if (inputMap)
345
- utils_1.extend(map, inputMap);
346
- if (options.mapBase)
347
- map = utils_1.rebaseMap(map, options.out ? path.dirname(path.resolve(options.out)) : process.cwd(), path.resolve(options.mapBase), true);
348
- const output = await config_file_1.serializeJson(map, style);
349
- if (options.out)
350
- await new Promise((resolve, reject) => fs.writeFile(options.out, output, err => err ? reject(err) : resolve()));
351
- else
352
- process.stdout.write(output);
353
- }
354
- break;
355
- case 're':
356
- case 'resolve':
357
- {
358
- let options;
359
- ({ args, options } = opts_1.readOptions(args, ['format', 'browser', 'react-native', 'production', 'electron', 'relative']));
360
- let env = common_1.readModuleEnv(options);
361
- let parent;
362
- if (args[1]) {
363
- let parentFormat;
364
- ({ resolved: parent, format: parentFormat } = api.resolveSync(args[1], setProjectPath ? projectPath + path.sep : undefined, env, true));
365
- if (parentFormat === 'builtin')
366
- parent = undefined;
367
- }
368
- else if (setProjectPath) {
369
- parent = projectPath + path.sep;
370
- }
371
- const resolved = api.resolveSync(args[0], parent, env, true);
372
- if (options.format) {
373
- console.log(resolved.format || '<undefined>');
374
- }
375
- else {
376
- resolved.resolved = resolved.resolved || '@empty';
377
- console.log(options.relative ? path.relative(process.cwd(), resolved.resolved) : resolved.resolved);
378
- }
379
- }
380
- break;
381
- case 'cl':
382
- case 'clean':
383
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
384
- await project.clean();
385
- break;
386
- case 'co':
387
- case 'checkout':
388
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
389
- await project.checkout(args);
390
- break;
391
- case 'un':
392
- case 'uninstall':
393
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
394
- await project.uninstall(args);
395
- break;
396
- case 'l':
397
- case 'link':
398
- {
399
- let options;
400
- ({ options, args } = opts_1.readOptions(args, [
401
- // TODO 'force', 'verify'
402
- ], [], ['override']));
403
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
404
- if (args.length === 2) {
405
- await project.link(args[0], args[1].indexOf(':') === -1 ? 'file:' + args[1] : args[1], options);
406
- }
407
- else if (args.length === 1) {
408
- const linkSource = 'file:' + path.resolve(args[0]);
409
- const target = await project.registryManager.resolveSource(linkSource, project.projectPath, project.projectPath);
410
- await project.install([{
411
- name: undefined,
412
- parent: undefined,
413
- target,
414
- type: package_1.DepType.primary
415
- }], options);
416
- }
417
- else if (args.length !== 1) {
418
- throw new common_1.JspmUserError(`Link command takes at most two arguments - an optional package name and a path.`);
419
- }
420
- }
421
- break;
422
- case 'ug':
423
- case 'upgrade':
424
- {
425
- // TODO: a single-major version upgrade of selected packages only
426
- // (does not accept no arguments)
427
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
428
- ui.warn('Still to be implemented.');
429
- }
430
- break;
431
- case 'un':
432
- case 'up':
433
- case 'unlink':
434
- case 'update':
435
- {
436
- // the name given here is not a "TARGET" but a "SELECTOR"
437
- let { options, args: selectors } = opts_1.readOptions(args, [
438
- // install options
439
- 'reset',
440
- 'latest'
441
- ], [], ['override']);
442
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
443
- await project.update(selectors, options);
444
- }
445
- break;
446
- case 'i':
447
- case 'install':
448
- {
449
- let { options, args: installArgs } = opts_1.readOptions(args, [
450
- // install options
451
- 'reset', 'force',
452
- // install type
453
- 'save-dev', 'dev', 'optional', 'peer',
454
- // constraint options
455
- 'exact', 'edge',
456
- // resolver options
457
- 'latest', 'lock',
458
- ], [], ['override']);
459
- if (options.force)
460
- throw new common_1.JspmUserError(`${common_1.highlight('--force')} flag is yet to be implemented. Use ${common_1.bold('jspm cc && jspm install')} for now, although this is only necessary if you have upgraded jspm or modified a globally linked dependency file.`);
461
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
462
- if (options.saveDev) {
463
- project.log.warn(`The ${common_1.bold(`--save-dev`)} install flag in jspm is just ${common_1.bold(`--dev`)}.`);
464
- options.dev = true;
465
- }
466
- let type;
467
- if (options.dev)
468
- type = package_1.DepType.dev;
469
- else if (options.peer)
470
- type = package_1.DepType.peer;
471
- else if (options.optional)
472
- type = package_1.DepType.optional;
473
- else
474
- type = package_1.DepType.primary;
475
- if (typeof options.override === 'string') {
476
- options.override = opts_1.readPropertySetters(options.override, true);
477
- if (options.override && installArgs.length > 1)
478
- throw new common_1.JspmUserError(`An override can only be specified through ${common_1.highlight(`-o`)} when installing a single dependency at a time.`);
479
- }
480
- if (projectPath === api_1.JSPM_GLOBAL_PATH && !options.lock) {
481
- options.latest = true;
482
- options.dedupe = false;
483
- }
484
- const installTargets = installArgs.map(arg => {
485
- /*
486
- * Assignment target install
487
- * jspm install x=y@1.2.3
488
- */
489
- let { name, target } = readTargetEquals(arg);
490
- // when name is undefined, install will auto-populate from target
491
- if (options.override)
492
- return { name, parent: undefined, target, type, override: options.override };
493
- else
494
- return { name, parent: undefined, target, type };
495
- });
496
- await project.install(installTargets, options);
497
- // TODO: look through install cache of install state for checked out and linked
498
- // and log that list so that the user is aware of it
499
- // await project.logInstallStates();
500
- }
501
- break;
502
- case 'b':
503
- case 'build':
504
- {
505
- let { options, args: buildArgs } = opts_1.readOptions(args, [
506
- 'clear-dir',
507
- 'mjs',
508
- 'node', 'bin', 'react-native', 'production', 'electron',
509
- 'show-graph',
510
- 'source-map',
511
- 'watch',
512
- 'exclude-deps',
513
- 'hash-entries',
514
- 'out',
515
- 'minify'
516
- ], ['map-base', 'dir', 'out', 'format', /* TODO: build map support 'map' */ , 'in'], ['external', 'banner']);
517
- if (options.node)
518
- (options.env = options.env || {}).node = true;
519
- if (options.bin)
520
- (options.env = options.env || {}).bin = true;
521
- if (options['react-native'])
522
- (options.env = options.env || {})['react-native'] = true;
523
- if (options.production)
524
- (options.env = options.env || {}).production = true;
525
- if (options.electron)
526
- (options.env = options.env || {}).electron = true;
527
- options.basePath = projectPath ? path.resolve(projectPath) : process.cwd();
528
- options.dir = options.dir || 'dist';
529
- let inputMap, style;
530
- if (options.in)
531
- ({ json: inputMap, style } = await config_file_1.readJSONStyled(options.in));
532
- if (options.map) {
533
- let buildMap, buildMapStyle;
534
- ({ json: buildMap, style: buildMapStyle } = await config_file_1.readJSONStyled(options.map));
535
- if (buildMap) {
536
- if (!style)
537
- style = buildMapStyle;
538
- utils_1.validateImportMap(path.relative(process.cwd(), path.resolve(options.map)), buildMap);
539
- options.map = buildMap;
540
- }
541
- else {
542
- throw new common_1.JspmUserError(`Import map ${path.relative(process.cwd(), path.resolve(options.map))} for build not found.`);
543
- }
544
- }
545
- if (options.external) {
546
- let externalMap, externalStyle;
547
- const externalsPath = path.resolve(options.external);
548
- try {
549
- ({ json: externalMap, style: externalStyle } = await config_file_1.readJSONStyled(externalsPath));
550
- }
551
- catch (e) {
552
- if (e.code !== 'ENOENT')
553
- throw e;
554
- }
555
- if (externalMap) {
556
- if (!style)
557
- style = externalStyle;
558
- utils_1.validateImportMap(path.relative(process.cwd(), externalsPath), externalMap);
559
- // scoped externals not currently supported, but could be (if thats even useful)
560
- options.external = utils_1.rebaseMap(externalMap, path.dirname(externalsPath), path.resolve(options.dir)).imports;
561
- }
562
- else {
563
- const external = {};
564
- options.external.split(' ').forEach(pair => {
565
- const aliasIndex = pair.indexOf('=');
566
- if (aliasIndex !== -1) {
567
- const externalName = pair.substr(0, aliasIndex);
568
- const aliasName = pair.substr(aliasIndex + 1);
569
- external[externalName] = aliasName;
570
- }
571
- else {
572
- external[pair] = true;
573
- }
574
- });
575
- if (Object.keys(external).length === 0)
576
- throw new common_1.JspmUserError(`${common_1.bold('jspm build --external')} requires an argument for externals.`);
577
- options.external = external;
578
- }
579
- }
580
- if (options.excludeDeps) {
581
- options.external = options.external || {};
582
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
583
- for (const dep in project.config.pjson.dependencies) {
584
- const depType = project.config.pjson.dependencies[dep].type;
585
- if (typeof depType === 'number' && depType !== package_1.DepType.dev) {
586
- options.external[dep] = true;
587
- }
588
- }
589
- }
590
- options.log = true;
591
- let absoluteMap = false;
592
- // -o with no arguments hides log due to using stdout
593
- if ('out' in options && !options.out && !options.showGraph)
594
- options.log = false;
595
- if (options.mapBase) {
596
- options.mapBase = path.resolve(options.mapBase);
597
- absoluteMap = true;
598
- }
599
- else if (options.out) {
600
- options.mapBase = path.dirname(path.resolve(options.out));
601
- }
602
- let outMap = await api.build(buildArgs, options);
603
- if (absoluteMap)
604
- outMap = utils_1.rebaseMap(outMap, options.mapBase, options.mapBase, true);
605
- if (inputMap)
606
- outMap = utils_1.extend(inputMap, outMap);
607
- if (options.flatScope)
608
- utils_1.flattenScopes(outMap);
609
- const output = await config_file_1.serializeJson(outMap, style || config_file_1.defaultStyle);
610
- if ('out' in options) {
611
- if (options.out)
612
- fs.writeFileSync(path.resolve(options.out), output);
613
- else
614
- process.stdout.write(output);
615
- }
616
- }
617
- break;
618
- case 're':
619
- case 'registry':
620
- if (args[0] !== 'config')
621
- throw new common_1.JspmUserError(`Unknown command ${common_1.bold(cmd)}.`);
622
- args = args.splice(1);
623
- case 'rc':
624
- case 'registry-config':
625
- if (args.length !== 1)
626
- throw new common_1.JspmUserError(`Only one argument expected for the registry name to configure.`);
627
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
628
- await project.registryConfig(args[0]);
629
- break;
630
- case 'c':
631
- case 'config':
632
- {
633
- let property, value;
634
- const unsetIndex = args.indexOf('--unset');
635
- const getIndex = args.indexOf('--get');
636
- if (unsetIndex !== -1) {
637
- if (args.length !== 2)
638
- throw new common_1.JspmUserError(`Only one configuration property is expected to be unset.`);
639
- if (unsetIndex === 1)
640
- property = args[0];
641
- else
642
- property = args[1];
643
- global_config_file_1.default.set(property, undefined);
644
- }
645
- else if (getIndex !== -1) {
646
- if (args.length !== 2)
647
- throw new common_1.JspmUserError(`Only one configuration property is expected to be read.`);
648
- if (getIndex === 1)
649
- property = args[0];
650
- else
651
- property = args[1];
652
- console.log(global_config_file_1.default.get(property));
653
- }
654
- else {
655
- property = args[0];
656
- value = opts_1.readValue(args.splice(1).join(' '));
657
- if (property === undefined || value === undefined)
658
- throw new common_1.JspmUserError(`jspm config requires a property and value via ${common_1.bold(`jspm config <property> <value>`)}`);
659
- global_config_file_1.default.set(property, value);
660
- }
661
- }
662
- break;
663
- case 'cc':
664
- case 'clear-cache':
665
- project = new api.Project(projectPath, { offline, preferOffline, userInput, cli: true });
666
- await project.clearCache();
667
- break;
668
- default:
669
- // if the cmd is a valid file, then we execute it directly
670
- let isFile = false;
671
- try {
672
- isFile = fs.statSync(cmd).isFile();
673
- }
674
- catch (e) { }
675
- if (isFile) {
676
- const exitCode = await api.exec([cmd, ...args]);
677
- process.exit(exitCode);
678
- return;
679
- }
680
- throw new common_1.JspmUserError(`Command or file ${common_1.bold([cmd, ...args].join(' '))} does not exist.`);
681
- }
682
- }
683
- catch (err) {
684
- if (process.env.globalJspm !== undefined) {
685
- if (err && err.hideStack)
686
- (project ? project.log.err.bind(project.log) : ui.err)(err.message || err);
687
- else
688
- (project ? project.log.err : ui.err)(err && err.stack || err);
689
- }
690
- throw err;
691
- }
692
- finally {
693
- if (project)
694
- await project.dispose();
695
- }
696
- }
697
- exports.default = cliHandler;
698
- if (process.env.globalJspm !== undefined)
699
- cliHandler(path.dirname(process.env.jspmConfigPath), process.argv[2], process.argv.slice(3))
700
- .then(() => process.exit(), _err => process.exit(1));
701
- //# sourceMappingURL=cli.js.map