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