lincd-cli 0.2.47 → 0.2.48

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.
package/lib/index.js CHANGED
@@ -1,67 +1,29 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __exportStar =
23
- (this && this.__exportStar) ||
24
- function (m, exports) {
25
- for (var p in m)
26
- if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- var __importDefault =
29
- (this && this.__importDefault) ||
30
- function (mod) {
31
- return mod && mod.__esModule ? mod : {default: mod};
32
- };
33
- Object.defineProperty(exports, '__esModule', {value: true});
34
- exports.generateWebpackConfig =
35
- exports.generateGruntConfig =
36
- exports.externaliseModules =
37
- exports.DeclarationPlugin =
38
- void 0;
39
- var declaration_plugin_1 = require('./plugins/declaration-plugin');
40
- Object.defineProperty(exports, 'DeclarationPlugin', {
41
- enumerable: true,
42
- get: function () {
43
- return __importDefault(declaration_plugin_1).default;
44
- },
45
- });
46
- var externalise_modules_1 = require('./plugins/externalise-modules');
47
- Object.defineProperty(exports, 'externaliseModules', {
48
- enumerable: true,
49
- get: function () {
50
- return __importDefault(externalise_modules_1).default;
51
- },
52
- });
53
- var config_grunt_1 = require('./config-grunt');
54
- Object.defineProperty(exports, 'generateGruntConfig', {
55
- enumerable: true,
56
- get: function () {
57
- return __importDefault(config_grunt_1).default;
58
- },
59
- });
60
- const config_webpack_1 = require('./config-webpack');
61
- Object.defineProperty(exports, 'generateWebpackConfig', {
62
- enumerable: true,
63
- get: function () {
64
- return config_webpack_1.generateWebpackConfig;
65
- },
66
- });
67
- __exportStar(require('./utils'), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.generateWebpackConfig = exports.generateGruntConfig = exports.externaliseModules = exports.DeclarationPlugin = void 0;
21
+ var declaration_plugin_1 = require("./plugins/declaration-plugin");
22
+ Object.defineProperty(exports, "DeclarationPlugin", { enumerable: true, get: function () { return __importDefault(declaration_plugin_1).default; } });
23
+ var externalise_modules_1 = require("./plugins/externalise-modules");
24
+ Object.defineProperty(exports, "externaliseModules", { enumerable: true, get: function () { return __importDefault(externalise_modules_1).default; } });
25
+ var config_grunt_1 = require("./config-grunt");
26
+ Object.defineProperty(exports, "generateGruntConfig", { enumerable: true, get: function () { return __importDefault(config_grunt_1).default; } });
27
+ const config_webpack_1 = require("./config-webpack");
28
+ Object.defineProperty(exports, "generateWebpackConfig", { enumerable: true, get: function () { return config_webpack_1.generateWebpackConfig; } });
29
+ __exportStar(require("./utils"), exports);
package/lib/interfaces.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', {value: true});
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,220 +1,244 @@
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');
5
- const path = require('path');
4
+ const colors = require("colors");
5
+ const path = require("path");
6
6
  const webpack = require('webpack');
7
- const {Compilation} = webpack;
8
-
7
+ const { Compilation } = webpack;
9
8
  class DeclarationPlugin {
10
- constructor(options = {}) {
11
- this.logMessages = true;
12
- this.exportRoot = '/lib';
13
- this.options = options;
14
- this.options['out'] = options.out ? options.out : './builds/declarations.d.ts';
15
- this.options['config'] = options.config ? options.config : process.cwd() + '/daconfig.js';
16
- //var moduleConfig = this.getModuleConfig();
17
- this.options['root'] = options.root || this.exportRoot; //'/lib'
18
- this.logMessages = options.debug ? options.debug : false;
19
- this.modulePackageInfo = require(process.cwd() + '/package.json');
20
- // this.debug('found package name: '+this.modulePackageInfo.name);
21
- }
22
-
23
- // apply(compiler) {
24
- // // Specify the event hook to attach to
25
- // compiler.hooks.emit.tapAsync(
26
- // 'MyExampleWebpackPlugin',
27
- // (compilation, callback) => {
28
- //
29
- // }
30
- apply(compiler) {
31
- this.debug('applying ');
32
- //when the compiler is ready to emit files
33
- // compiler.plugin('emit', (compilation,callback) =>
34
- compiler.hooks.compilation.tap('DeclarationPlugin', (compilation) => {
35
- //NOTE: even though the stage comes from the processAssets hook and not the afterProcessAssets hook
36
- // somehow this only works WITH the stage defined
37
- compilation.hooks.afterProcessAssets.tap(
38
- {
39
- stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
40
- name: 'DeclarationPlugin',
41
- },
42
- () => {
43
- // this.debug('indexing and removing declaration assets');
44
- //collect all generated declaration files
45
- //and remove them from the assets that will be emitted
46
- //NOTE: at some point we decided to overwrite declaration files between emits because sometimes only one new declaration file is emitted
47
- //this may cause issues when you remove a file during the continuous building process, but better than the other way around for now
48
- if (!this.declarationFiles) {
49
- this.declarationFiles = {};
50
- }
51
- compilation.getAssets().forEach((asset, key) => {
52
- // this.debug('key '+key.toString())
53
- // this.debug('value '+Object.getOwnPropertyNames(asset).join(", "))
54
- // this.debug('asset: ' + asset.name);
55
- if (asset.name.indexOf('.d.ts') !== -1) {
56
- if (this.declarationFiles[asset.name]) {
57
- this.debug('overwriting ' + asset.name);
58
- }
59
- this.declarationFiles[asset.name] = asset;
60
- this.debug('indexed and removed asset: ' + colors.green(asset.name));
61
- compilation.deleteAsset(asset.name);
62
- }
63
- });
64
- if (Object.keys(this.declarationFiles).length == 0) {
65
- this.debug(
66
- "Didn't build .d.ts file because no declaration assets were emitted during build process.".yellow,
67
- );
68
- this.debug('This is likely because webpack is using cache.'.yellow);
69
- this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'.yellow);
70
- // this.log('Make sure to run '.yellow + 'tsc'.blue + ' before running webpack'.yellow);
71
- // this.log(
72
- // 'Make sure to test for '.yellow +
73
- // '/(?!.*.d.ts).ts(x?)$/'.blue.bold['underline'] +
74
- // ' in the ts-loader in webpack.config.json'.yellow,
75
- // );
76
- // this.log(('Assets: ' + Object.keys(compilation.assets).toString()).yellow);
77
- // callback();
78
- return;
79
- }
80
- //combine them into one declaration file
81
- var combinedDeclaration = this.generateCombinedDeclaration(this.declarationFiles); //moduleConfig
82
- //and insert that back into the assets
83
- // compilation.assets[this.options.out] = {
84
- // source: function() {
85
- // return combinedDeclaration;
86
- // },
87
- // size: function() {
88
- // return combinedDeclaration.length;
89
- // },
90
- // };
91
- // As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
92
- compilation.emitAsset(this.options.out, new webpack.sources.RawSource(combinedDeclaration));
93
- //get meta data from module exports
94
- /*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
95
- //and insert that back into the assets as [module_name].meta.json
96
- compilation.assets[this.options.out.replace(".d.ts",".meta.rdf.json")] = {
97
- source: function() {
98
- return metaRdfJson;
99
- },
100
- size: function() {
101
- return metaRdfJson.length;
102
- }
103
- };*/
104
- //}
105
- },
106
- );
107
- });
108
- }
109
-
110
- debug(...msgs) {
111
- msgs.unshift('declarations:');
112
- if (this.logMessages) {
113
- console.log.apply(null, msgs);
9
+ constructor(options = {}) {
10
+ this.logMessages = true;
11
+ this.exportRoot = '/lib';
12
+ this.options = options;
13
+ this.options['out'] = options.out
14
+ ? options.out
15
+ : './builds/declarations.d.ts';
16
+ this.options['config'] = options.config
17
+ ? options.config
18
+ : process.cwd() + '/daconfig.js';
19
+ //var moduleConfig = this.getModuleConfig();
20
+ this.options['root'] = options.root || this.exportRoot; //'/lib'
21
+ this.logMessages = options.debug ? options.debug : false;
22
+ this.modulePackageInfo = require(process.cwd() + '/package.json');
23
+ // this.debug('found package name: '+this.modulePackageInfo.name);
24
+ }
25
+ // apply(compiler) {
26
+ // // Specify the event hook to attach to
27
+ // compiler.hooks.emit.tapAsync(
28
+ // 'MyExampleWebpackPlugin',
29
+ // (compilation, callback) => {
30
+ //
31
+ // }
32
+ apply(compiler) {
33
+ this.debug('applying ');
34
+ //when the compiler is ready to emit files
35
+ // compiler.plugin('emit', (compilation,callback) =>
36
+ compiler.hooks.compilation.tap('DeclarationPlugin', (compilation) => {
37
+ //NOTE: even though the stage comes from the processAssets hook and not the afterProcessAssets hook
38
+ // somehow this only works WITH the stage defined
39
+ compilation.hooks.afterProcessAssets.tap({
40
+ stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
41
+ name: 'DeclarationPlugin',
42
+ }, () => {
43
+ // this.debug('indexing and removing declaration assets');
44
+ //collect all generated declaration files
45
+ //and remove them from the assets that will be emitted
46
+ //NOTE: at some point we decided to overwrite declaration files between emits because sometimes only one new declaration file is emitted
47
+ //this may cause issues when you remove a file during the continuous building process, but better than the other way around for now
48
+ if (!this.declarationFiles) {
49
+ this.declarationFiles = {};
50
+ }
51
+ compilation.getAssets().forEach((asset, key) => {
52
+ // this.debug('key '+key.toString())
53
+ // this.debug('value '+Object.getOwnPropertyNames(asset).join(", "))
54
+ // this.debug('asset: ' + asset.name);
55
+ if (asset.name.indexOf('.d.ts') !== -1) {
56
+ if (this.declarationFiles[asset.name]) {
57
+ this.debug('overwriting ' + asset.name);
58
+ }
59
+ this.declarationFiles[asset.name] = asset;
60
+ this.debug('indexed and removed asset: ' + colors.green(asset.name));
61
+ compilation.deleteAsset(asset.name);
62
+ }
63
+ });
64
+ if (Object.keys(this.declarationFiles).length == 0) {
65
+ this.debug("Didn't build .d.ts file because no declaration assets were emitted during build process."
66
+ .yellow);
67
+ this.debug('This is likely because webpack is using cache.'.yellow);
68
+ this.debug('In watch mode, declaration assets will be emitted once you change a ts(x) source file'
69
+ .yellow);
70
+ // this.log('Make sure to run '.yellow + 'tsc'.blue + ' before running webpack'.yellow);
71
+ // this.log(
72
+ // 'Make sure to test for '.yellow +
73
+ // '/(?!.*.d.ts).ts(x?)$/'.blue.bold['underline'] +
74
+ // ' in the ts-loader in webpack.config.json'.yellow,
75
+ // );
76
+ // this.log(('Assets: ' + Object.keys(compilation.assets).toString()).yellow);
77
+ // callback();
78
+ return;
79
+ }
80
+ //combine them into one declaration file
81
+ var combinedDeclaration = this.generateCombinedDeclaration(this.declarationFiles); //moduleConfig
82
+ //and insert that back into the assets
83
+ // compilation.assets[this.options.out] = {
84
+ // source: function() {
85
+ // return combinedDeclaration;
86
+ // },
87
+ // size: function() {
88
+ // return combinedDeclaration.length;
89
+ // },
90
+ // };
91
+ // As suggested by @JonWallsten here: https://github.com/TypeStrong/ts-loader/pull/1251#issuecomment-800032753
92
+ compilation.emitAsset(this.options.out, new webpack.sources.RawSource(combinedDeclaration));
93
+ //get meta data from module exports
94
+ /*var metaRdfJson = this.generateMetaRdfJson(compilation,moduleConfig);
95
+ //and insert that back into the assets as [module_name].meta.json
96
+ compilation.assets[this.options.out.replace(".d.ts",".meta.rdf.json")] = {
97
+ source: function() {
98
+ return metaRdfJson;
99
+ },
100
+ size: function() {
101
+ return metaRdfJson.length;
102
+ }
103
+ };*/
104
+ //}
105
+ });
106
+ });
107
+ }
108
+ debug(...msgs) {
109
+ msgs.unshift('declarations:');
110
+ if (this.logMessages) {
111
+ console.log.apply(null, msgs);
112
+ }
114
113
  }
115
- }
116
-
117
- log(...msgs) {
118
- msgs.unshift('declarations:');
119
- console.log.apply(null, msgs);
120
- }
121
-
122
- generateCombinedDeclaration(declarationFiles) {
123
- this.debug('generating combined declaration');
124
- var declarations = '';
125
- //this.debug("daCore: using config ",moduleConfig);
126
- //this.debug("Combining these files:"+Object.keys(declarationFiles).toString());
127
- //get current directory that webpack is run from (base of project), and replace backward slashes by forward ones to compare
128
- var basePath = process.cwd().replace(/\\/g, '/') + '/';
129
- this.debug('Base path:', colors.blue(basePath));
130
- var npmModuleName = this.modulePackageInfo.name;
131
- // let moduleName = npmModuleName.replace(/\@\w+\//, '');
132
- var importMap = {};
133
- for (var declarationFileName in declarationFiles) {
134
- //this.debug("Parsing "+declarationFileName);
135
- var declarationFile = declarationFiles[declarationFileName];
136
- var data = declarationFile.source.source();
137
- if (!data.split) {
138
- console.warn(typeof data, declarationFileName + ' - cannot split declaration contents. Not a string?');
139
- continue;
140
- }
141
- var lines = data.split('\n');
142
- var i = lines.length;
143
- while (i--) {
144
- var line = lines[i];
145
- //exclude empty lines
146
- var excludeLine = line == '';
147
- //if importing something, or re-exporting something
148
- if (/import ([a-z0-9A-Z_\-\*\{\}\s,]+)/.test(line) || /export ([a-z0-9A-Z_-\{\}\s,\*]+) from/.test(line)) {
149
- var fileImports = line.indexOf('"') !== -1 ? line.match(/\"([^\"]+)\"/) : line.match(/\'([^\']+)\'/);
150
- if (fileImports && fileImports.length > 1) {
151
- var importPath = fileImports[1];
152
- //if it is importing a relative path and it is a new one
153
- if ((importPath.substr(0, 2) == './' || importPath.substr(0, 3) == '../') && !importMap[importPath]) {
154
- //we will replace it with the local npm module later, calc and save the absolute path for now
155
- //we parse from builds, because now TS-LOADER gives paths relative to its output folder
156
- let parsed = path.parse('./builds/' + declarationFileName);
157
- let fileDirectory = parsed.dir;
158
- var absoluteImportPath = path.resolve(fileDirectory, importPath);
159
- // this.debug('declarationfilename '+declarationFileName);
160
- // this.debug('filedir '+fileDirectory);
161
- this.debug('import ' + colors.blue(importPath), ' -> ' + colors.green(absoluteImportPath));
162
- importMap[importPath] = absoluteImportPath;
114
+ log(...msgs) {
115
+ msgs.unshift('declarations:');
116
+ console.log.apply(null, msgs);
117
+ }
118
+ generateCombinedDeclaration(declarationFiles) {
119
+ this.debug('generating combined declaration');
120
+ var declarations = '';
121
+ //this.debug("daCore: using config ",moduleConfig);
122
+ //this.debug("Combining these files:"+Object.keys(declarationFiles).toString());
123
+ //get current directory that webpack is run from (base of project), and replace backward slashes by forward ones to compare
124
+ var basePath = process.cwd().replace(/\\/g, '/') + '/';
125
+ this.debug('Base path:', colors.blue(basePath));
126
+ var npmModuleName = this.modulePackageInfo.name;
127
+ // let moduleName = npmModuleName.replace(/\@\w+\//, '');
128
+ var importMap = {};
129
+ for (var declarationFileName in declarationFiles) {
130
+ //this.debug("Parsing "+declarationFileName);
131
+ var declarationFile = declarationFiles[declarationFileName];
132
+ var data = declarationFile.source.source();
133
+ if (!data.split) {
134
+ console.warn(typeof data, declarationFileName +
135
+ ' - cannot split declaration contents. Not a string?');
136
+ continue;
137
+ }
138
+ var lines = data.split('\n');
139
+ var i = lines.length;
140
+ while (i--) {
141
+ var line = lines[i];
142
+ //exclude empty lines
143
+ var excludeLine = line == '';
144
+ //if importing something, or re-exporting something
145
+ if (/import ([a-z0-9A-Z_\-\*\{\}\s,]+)/.test(line) ||
146
+ /export ([a-z0-9A-Z_-\{\}\s,\*]+) from/.test(line)) {
147
+ var fileImports = line.indexOf('"') !== -1
148
+ ? line.match(/\"([^\"]+)\"/)
149
+ : line.match(/\'([^\']+)\'/);
150
+ if (fileImports && fileImports.length > 1) {
151
+ var importPath = fileImports[1];
152
+ //if it is importing a relative path and it is a new one
153
+ if ((importPath.substr(0, 2) == './' ||
154
+ importPath.substr(0, 3) == '../') &&
155
+ !importMap[importPath]) {
156
+ //we will replace it with the local npm module later, calc and save the absolute path for now
157
+ //we parse from builds, because now TS-LOADER gives paths relative to its output folder
158
+ let parsed = path.parse('./builds/' + declarationFileName);
159
+ let fileDirectory = parsed.dir;
160
+ var absoluteImportPath = path.resolve(fileDirectory, importPath);
161
+ // this.debug('declarationfilename '+declarationFileName);
162
+ // this.debug('filedir '+fileDirectory);
163
+ this.debug('import ' + colors.blue(importPath), ' -> ' + colors.green(absoluteImportPath));
164
+ importMap[importPath] = absoluteImportPath;
165
+ }
166
+ }
167
+ }
168
+ //exclude re-exports
169
+ //excludeLine = excludeLine || (/export ([a-z0-9A-Z_-\{\}\s,\*]+) from/).test(line);
170
+ //exclude unnamed local imports like: import "./some.scss" or import "./someFile"t
171
+ excludeLine =
172
+ excludeLine || /import ["'][a-z0-9A-Z_\-.\/\\]+["']/.test(line);
173
+ //if defined, check for excluded references
174
+ if (!excludeLine &&
175
+ this.excludedReferences &&
176
+ line.indexOf('<reference') !== -1) {
177
+ excludeLine = this.excludedReferences.some((reference) => line.indexOf(reference) !== -1);
178
+ }
179
+ if (excludeLine) {
180
+ this.debug('Excluding line ' + i + ': ' + line);
181
+ lines.splice(i, 1);
182
+ }
183
+ else {
184
+ if (line.indexOf('declare ') !== -1) {
185
+ lines[i] = line.replace('declare ', '');
186
+ }
187
+ //add tab
188
+ lines[i] = lines[i];
189
+ }
163
190
  }
164
- }
191
+ //TS Loader now uses paths relative to output dir. so here we remove a single ../ from the path (which is in there because /builds is the output dir and /lib is the relative path of the file)
192
+ let fixedDeclarationPath = declarationFileName
193
+ .replace(/\\/g, '/')
194
+ .replace('../', '')
195
+ .replace('.d.ts', '');
196
+ var moduleDeclaration = npmModuleName + '/' + fixedDeclarationPath;
197
+ //this.debug('basePath:'+basePath);
198
+ declarations +=
199
+ "declare module '" +
200
+ moduleDeclaration +
201
+ "' {\n\t" +
202
+ lines.join('\n\t') +
203
+ '\n}\n\n';
204
+ this.debug('Defining module ' +
205
+ colors.yellow(moduleDeclaration) +
206
+ ' from ' +
207
+ colors.blue(declarationFileName));
165
208
  }
166
- //exclude re-exports
167
- //excludeLine = excludeLine || (/export ([a-z0-9A-Z_-\{\}\s,\*]+) from/).test(line);
168
- //exclude unnamed local imports like: import "./some.scss" or import "./someFile"t
169
- excludeLine = excludeLine || /import ["'][a-z0-9A-Z_\-.\/\\]+["']/.test(line);
170
- //if defined, check for excluded references
171
- if (!excludeLine && this.excludedReferences && line.indexOf('<reference') !== -1) {
172
- excludeLine = this.excludedReferences.some((reference) => line.indexOf(reference) !== -1);
209
+ for (var relativeImportPath in importMap) {
210
+ let absoluteImportPath = importMap[relativeImportPath];
211
+ let npmImportModule = npmModuleName +
212
+ '/' +
213
+ absoluteImportPath
214
+ .substr(basePath.length)
215
+ .replace('.d.ts', '')
216
+ .replace(/\\/g, '/');
217
+ this.debug('Replacing ' +
218
+ colors.blue(relativeImportPath) +
219
+ ' with ' +
220
+ colors.yellow(npmImportModule));
221
+ //wrap in quotes to omit problems with replacing partials and having to fix order of replacements
222
+ declarations = declarations.replace(new RegExp('(\'|")' + relativeImportPath + '(\'|")', 'g'), '"' + npmImportModule + '"');
173
223
  }
174
- if (excludeLine) {
175
- this.debug('Excluding line ' + i + ': ' + line);
176
- lines.splice(i, 1);
177
- } else {
178
- if (line.indexOf('declare ') !== -1) {
179
- lines[i] = line.replace('declare ', '');
180
- }
181
- //add tab
182
- lines[i] = lines[i];
224
+ let indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
225
+ this.debug('Replacing index ' +
226
+ colors.yellow(indexModulePath) +
227
+ ' with ' +
228
+ colors.yellow(this.modulePackageInfo.name));
229
+ declarations = declarations.replace("'" + indexModulePath + "'", "'" + this.modulePackageInfo.name + "'");
230
+ //replace alias
231
+ if (this.options.alias) {
232
+ for (let aliasKey in this.options.alias) {
233
+ //declarations = declarations.replace(aliasKey,this.options.alias[aliasKey]);
234
+ this.debug('Replacing alias ' +
235
+ aliasKey +
236
+ ' with ' +
237
+ this.options.alias[aliasKey]);
238
+ declarations = declarations.replace(new RegExp(aliasKey, 'g'), this.options.alias[aliasKey]);
239
+ }
183
240
  }
184
- }
185
- //TS Loader now uses paths relative to output dir. so here we remove a single ../ from the path (which is in there because /builds is the output dir and /lib is the relative path of the file)
186
- let fixedDeclarationPath = declarationFileName.replace(/\\/g, '/').replace('../', '').replace('.d.ts', '');
187
- var moduleDeclaration = npmModuleName + '/' + fixedDeclarationPath;
188
- //this.debug('basePath:'+basePath);
189
- declarations += "declare module '" + moduleDeclaration + "' {\n\t" + lines.join('\n\t') + '\n}\n\n';
190
- this.debug('Defining module ' + colors.yellow(moduleDeclaration) + ' from ' + colors.blue(declarationFileName));
191
- }
192
- for (var relativeImportPath in importMap) {
193
- let absoluteImportPath = importMap[relativeImportPath];
194
- let npmImportModule =
195
- npmModuleName + '/' + absoluteImportPath.substr(basePath.length).replace('.d.ts', '').replace(/\\/g, '/');
196
- this.debug('Replacing ' + colors.blue(relativeImportPath) + ' with ' + colors.yellow(npmImportModule));
197
- //wrap in quotes to omit problems with replacing partials and having to fix order of replacements
198
- declarations = declarations.replace(
199
- new RegExp('(\'|")' + relativeImportPath + '(\'|")', 'g'),
200
- '"' + npmImportModule + '"',
201
- );
202
- }
203
- let indexModulePath = this.modulePackageInfo.name + this.exportRoot + '/index';
204
- this.debug(
205
- 'Replacing index ' + colors.yellow(indexModulePath) + ' with ' + colors.yellow(this.modulePackageInfo.name),
206
- );
207
- declarations = declarations.replace("'" + indexModulePath + "'", "'" + this.modulePackageInfo.name + "'");
208
- //replace alias
209
- if (this.options.alias) {
210
- for (let aliasKey in this.options.alias) {
211
- //declarations = declarations.replace(aliasKey,this.options.alias[aliasKey]);
212
- this.debug('Replacing alias ' + aliasKey + ' with ' + this.options.alias[aliasKey]);
213
- declarations = declarations.replace(new RegExp(aliasKey, 'g'), this.options.alias[aliasKey]);
214
- }
241
+ return declarations;
215
242
  }
216
- return declarations;
217
- }
218
243
  }
219
-
220
244
  exports.default = DeclarationPlugin;