@servicetitan/startup 31.0.0 → 31.2.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.
- package/bin/index.js +8 -0
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +1 -7
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/prepare-package.d.ts +1 -2
- package/dist/cli/commands/prepare-package.d.ts.map +1 -1
- package/dist/cli/commands/prepare-package.js +4 -6
- package/dist/cli/commands/prepare-package.js.map +1 -1
- package/dist/cli/commands/run-task.test.js +59 -0
- package/dist/cli/commands/run-task.test.js.map +1 -0
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +2 -11
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/tasks/swc-cli.d.js +3 -0
- package/dist/cli/tasks/swc-cli.d.js.map +1 -0
- package/dist/cli/tasks/swc-compile-package.d.ts.map +1 -1
- package/dist/cli/tasks/swc-compile-package.js +22 -19
- package/dist/cli/tasks/swc-compile-package.js.map +1 -1
- package/dist/cli/types/cpx2.d.js +3 -0
- package/dist/cli/types/cpx2.d.js.map +1 -0
- package/dist/cli/utils/bundle.d.ts +2 -2
- package/dist/cli/utils/bundle.d.ts.map +1 -1
- package/dist/cli/utils/bundle.js +18 -4
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/cli/utils/copy-files.d.ts +1 -1
- package/dist/cli/utils/copy-files.d.ts.map +1 -1
- package/dist/cli/utils/copy-files.js +18 -11
- package/dist/cli/utils/copy-files.js.map +1 -1
- package/dist/cli/utils/get-module-type.d.ts.map +1 -1
- package/dist/cli/utils/get-module-type.js +2 -16
- package/dist/cli/utils/get-module-type.js.map +1 -1
- package/dist/cli/utils/index.d.ts +1 -1
- package/dist/cli/utils/index.d.ts.map +1 -1
- package/dist/cli/utils/index.js +1 -1
- package/dist/cli/utils/index.js.map +1 -1
- package/dist/cli/utils/ts-config.d.ts +11 -0
- package/dist/cli/utils/ts-config.d.ts.map +1 -0
- package/dist/cli/utils/ts-config.js +80 -0
- package/dist/cli/utils/ts-config.js.map +1 -0
- package/dist/utils/get-configuration.d.ts +1 -0
- package/dist/utils/get-configuration.d.ts.map +1 -1
- package/dist/utils/get-configuration.js +14 -0
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.d.ts.map +1 -1
- package/dist/utils/log.js +9 -0
- package/dist/utils/log.js.map +1 -1
- package/dist/webpack/configs/dev-server-config.d.ts.map +1 -1
- package/dist/webpack/configs/dev-server-config.js +11 -0
- package/dist/webpack/configs/dev-server-config.js.map +1 -1
- package/dist/webpack/configs/index.d.ts +0 -1
- package/dist/webpack/configs/index.d.ts.map +1 -1
- package/dist/webpack/configs/index.js +0 -1
- package/dist/webpack/configs/index.js.map +1 -1
- package/dist/webpack/configs/optimization-config.js +6 -6
- package/dist/webpack/configs/optimization-config.js.map +1 -1
- package/dist/webpack/configs/output-config.d.ts.map +1 -1
- package/dist/webpack/configs/output-config.js +3 -2
- package/dist/webpack/configs/output-config.js.map +1 -1
- package/dist/webpack/configs/plugins/html-plugin.d.ts +1 -1
- package/dist/webpack/configs/plugins/html-plugin.d.ts.map +1 -1
- package/dist/webpack/configs/plugins/html-plugin.js +2 -2
- package/dist/webpack/configs/plugins/html-plugin.js.map +1 -1
- package/dist/webpack/configs/plugins/virtual-modules-plugin.js +14 -4
- package/dist/webpack/configs/plugins/virtual-modules-plugin.js.map +1 -1
- package/dist/webpack/configs/utils/generate-metadata.d.ts.map +1 -1
- package/dist/webpack/configs/utils/generate-metadata.js +4 -0
- package/dist/webpack/configs/utils/generate-metadata.js.map +1 -1
- package/dist/webpack/create-webpack-config.d.ts.map +1 -1
- package/dist/webpack/create-webpack-config.js +0 -1
- package/dist/webpack/create-webpack-config.js.map +1 -1
- package/dist/webpack/types.d.ts +1 -0
- package/dist/webpack/types.d.ts.map +1 -1
- package/dist/webpack/utils/index.d.ts +0 -1
- package/dist/webpack/utils/index.d.ts.map +1 -1
- package/dist/webpack/utils/index.js +0 -1
- package/dist/webpack/utils/index.js.map +1 -1
- package/package.json +7 -8
- package/src/cli/commands/__tests__/build.test.ts +2 -4
- package/src/cli/commands/__tests__/prepare-package.test.ts +5 -28
- package/src/cli/commands/__tests__/start.test.ts +3 -5
- package/src/cli/commands/build.ts +0 -2
- package/src/cli/commands/prepare-package.ts +4 -7
- package/src/cli/commands/start.ts +1 -3
- package/src/cli/tasks/__tests__/swc-compile-package.test.ts +71 -12
- package/src/cli/tasks/swc-compile-package.ts +21 -20
- package/src/cli/utils/__tests__/bundle.test.ts +48 -7
- package/src/cli/utils/__tests__/copy-files.test.ts +5 -5
- package/src/cli/utils/bundle.ts +27 -5
- package/src/cli/utils/copy-files.ts +16 -6
- package/src/cli/utils/get-module-type.ts +2 -18
- package/src/cli/utils/index.ts +1 -1
- package/src/cli/utils/ts-config.ts +64 -0
- package/src/utils/__tests__/get-configuration.test.ts +20 -0
- package/src/utils/__tests__/log.test.ts +8 -0
- package/src/utils/get-configuration.ts +12 -0
- package/src/utils/log.ts +10 -0
- package/src/webpack/__tests__/create-webpack-config-shared-dependencies.test.ts +0 -1
- package/src/webpack/__tests__/create-webpack-config-web-component.test.ts +17 -28
- package/src/webpack/__tests__/create-webpack-config.test.ts +113 -42
- package/src/webpack/configs/dev-server-config.ts +13 -1
- package/src/webpack/configs/index.ts +0 -1
- package/src/webpack/configs/optimization-config.ts +6 -6
- package/src/webpack/configs/output-config.ts +4 -2
- package/src/webpack/configs/plugins/html-plugin.ts +5 -2
- package/src/webpack/configs/plugins/virtual-modules-plugin.ts +15 -2
- package/src/webpack/configs/utils/__tests__/generate-metadata.test.ts +3 -1
- package/src/webpack/configs/utils/generate-metadata.ts +6 -1
- package/src/webpack/create-webpack-config.ts +0 -2
- package/src/webpack/types.ts +1 -0
- package/src/webpack/utils/index.ts +0 -1
- package/dist/__mocks__/create-package.d.ts +0 -3
- package/dist/__mocks__/create-package.d.ts.map +0 -1
- package/dist/__mocks__/index.d.ts +0 -2
- package/dist/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/__mocks__/expect-calls.d.ts +0 -23
- package/dist/cli/commands/review/__mocks__/expect-calls.d.ts.map +0 -1
- package/dist/cli/commands/review/__mocks__/index.d.ts +0 -2
- package/dist/cli/commands/review/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/index.d.ts +0 -4
- package/dist/cli/commands/review/rules/__mocks__/index.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-config.d.ts +0 -7
- package/dist/cli/commands/review/rules/__mocks__/mock-config.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-packages.d.ts +0 -21
- package/dist/cli/commands/review/rules/__mocks__/mock-packages.d.ts.map +0 -1
- package/dist/cli/commands/review/rules/__mocks__/mock-project.d.ts +0 -3
- package/dist/cli/commands/review/rules/__mocks__/mock-project.d.ts.map +0 -1
- package/dist/cli/utils/style-extensions.d.ts +0 -2
- package/dist/cli/utils/style-extensions.d.ts.map +0 -1
- package/dist/cli/utils/style-extensions.js +0 -17
- package/dist/cli/utils/style-extensions.js.map +0 -1
- package/dist/cli/utils/tcm.d.ts +0 -6
- package/dist/cli/utils/tcm.d.ts.map +0 -1
- package/dist/cli/utils/tcm.js +0 -72
- package/dist/cli/utils/tcm.js.map +0 -1
- package/dist/webpack/__mocks__/file-rules.d.ts +0 -3
- package/dist/webpack/__mocks__/file-rules.d.ts.map +0 -1
- package/dist/webpack/__mocks__/index.d.ts +0 -3
- package/dist/webpack/__mocks__/index.d.ts.map +0 -1
- package/dist/webpack/__mocks__/style-rules.d.ts +0 -8
- package/dist/webpack/__mocks__/style-rules.d.ts.map +0 -1
- package/dist/webpack/configs/cache-config.d.ts +0 -6
- package/dist/webpack/configs/cache-config.d.ts.map +0 -1
- package/dist/webpack/configs/cache-config.js +0 -34
- package/dist/webpack/configs/cache-config.js.map +0 -1
- package/dist/webpack/utils/feature-cohort.d.ts +0 -5
- package/dist/webpack/utils/feature-cohort.d.ts.map +0 -1
- package/dist/webpack/utils/feature-cohort.js +0 -26
- package/dist/webpack/utils/feature-cohort.js.map +0 -1
- package/dist/webpack/utils/hash-mod.d.ts +0 -9
- package/dist/webpack/utils/hash-mod.d.ts.map +0 -1
- package/dist/webpack/utils/hash-mod.js +0 -39
- package/dist/webpack/utils/hash-mod.js.map +0 -1
- package/src/cli/utils/__tests__/tcm.test.ts +0 -195
- package/src/cli/utils/style-extensions.ts +0 -1
- package/src/cli/utils/tcm.ts +0 -66
- package/src/webpack/configs/cache-config.ts +0 -25
- package/src/webpack/utils/feature-cohort.ts +0 -19
- package/src/webpack/utils/hash-mod.ts +0 -32
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "styleExtensions", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return styleExtensions;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const styleExtensions = [
|
|
12
|
-
'css',
|
|
13
|
-
'less',
|
|
14
|
-
'scss'
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=style-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/utils/style-extensions.ts"],"sourcesContent":["export const styleExtensions = ['css', 'less', 'scss'];\n"],"names":["styleExtensions"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,kBAAkB;IAAC;IAAO;IAAQ;CAAO"}
|
package/dist/cli/utils/tcm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tcm.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/tcm.ts"],"names":[],"mappings":"AASA,UAAU,UAAU;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAWD,wBAAsB,GAAG,CAAC,EAAE,KAAK,EAAE,GAAE,UAAe,iBAiCnD"}
|
package/dist/cli/utils/tcm.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "tcm", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return tcm;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _glob = require("glob");
|
|
12
|
-
const _chokidar = /*#__PURE__*/ _interop_require_default(require("chokidar"));
|
|
13
|
-
const _typedcssmodules = /*#__PURE__*/ _interop_require_default(require("typed-css-modules"));
|
|
14
|
-
const _utils = require("../../utils");
|
|
15
|
-
const _compileless = require("./compile-less");
|
|
16
|
-
const _compilesass = require("./compile-sass");
|
|
17
|
-
const _styleextensions = require("./style-extensions");
|
|
18
|
-
function _interop_require_default(obj) {
|
|
19
|
-
return obj && obj.__esModule ? obj : {
|
|
20
|
-
default: obj
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async function compile(filePath) {
|
|
24
|
-
if (filePath.endsWith('.less')) {
|
|
25
|
-
return (0, _compileless.compileLess)(filePath);
|
|
26
|
-
}
|
|
27
|
-
if (filePath.endsWith('.scss')) {
|
|
28
|
-
return (0, _compilesass.compileSass)(filePath);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async function tcm({ watch } = {}) {
|
|
32
|
-
const source = (0, _utils.getFolders)().source.replace(/\\/g, '/');
|
|
33
|
-
const filesPattern = `${source}/**/*.module.{${_styleextensions.styleExtensions.join()}}`;
|
|
34
|
-
const creator = new _typedcssmodules.default({
|
|
35
|
-
camelCase: true,
|
|
36
|
-
namedExports: true
|
|
37
|
-
});
|
|
38
|
-
const generateDefinitions = async (file)=>{
|
|
39
|
-
try {
|
|
40
|
-
const css = await compile(file);
|
|
41
|
-
const content = await creator.create(file, css, !!watch);
|
|
42
|
-
await content.writeFile();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
_utils.log.error(String(error));
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
if (!watch) {
|
|
48
|
-
_utils.log.info(`Generating types for ${filesPattern}`);
|
|
49
|
-
const files = await (0, _glob.glob)(filesPattern);
|
|
50
|
-
await Promise.all(files.map(generateDefinitions));
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
_utils.log.info(`Watching to generate types for ${filesPattern}`);
|
|
54
|
-
watchFiles(source, async (path)=>{
|
|
55
|
-
_utils.log.debug('tcm', `Compiling ${path}`);
|
|
56
|
-
await generateDefinitions(path);
|
|
57
|
-
});
|
|
58
|
-
/* istanbul ignore next: not executed in test environment */ if (process.env.NODE_ENV !== 'test') {
|
|
59
|
-
await new Promise(()=>{});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function watchFiles(source, callback) {
|
|
63
|
-
const stylesRegex = new RegExp(`\\.module\\.(${_styleextensions.styleExtensions.join('|')})$`);
|
|
64
|
-
const watcher = _chokidar.default.watch(source, {
|
|
65
|
-
ignored: (path, stats)=>!!(stats === null || stats === void 0 ? void 0 : stats.isFile()) && !stylesRegex.test(path),
|
|
66
|
-
ignoreInitial: true
|
|
67
|
-
});
|
|
68
|
-
watcher.on('add', callback);
|
|
69
|
-
watcher.on('change', callback);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=tcm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/cli/utils/tcm.ts"],"sourcesContent":["import { glob } from 'glob';\nimport chokidar from 'chokidar';\nimport DtsCreator from 'typed-css-modules';\n\nimport { getFolders, log } from '../../utils';\nimport { compileLess } from './compile-less';\nimport { compileSass } from './compile-sass';\nimport { styleExtensions } from './style-extensions';\n\ninterface RunOptions {\n watch?: boolean;\n}\n\nasync function compile(filePath: string) {\n if (filePath.endsWith('.less')) {\n return compileLess(filePath);\n }\n if (filePath.endsWith('.scss')) {\n return compileSass(filePath);\n }\n}\n\nexport async function tcm({ watch }: RunOptions = {}) {\n const source = getFolders().source.replace(/\\\\/g, '/');\n const filesPattern = `${source}/**/*.module.{${styleExtensions.join()}}`;\n const creator = new DtsCreator({ camelCase: true, namedExports: true });\n\n const generateDefinitions = async (file: string) => {\n try {\n const css = await compile(file);\n const content = await creator.create(file, css, !!watch);\n await content.writeFile();\n } catch (error) {\n log.error(String(error));\n }\n };\n\n if (!watch) {\n log.info(`Generating types for ${filesPattern}`);\n const files = await glob(filesPattern);\n await Promise.all(files.map(generateDefinitions));\n return;\n }\n\n log.info(`Watching to generate types for ${filesPattern}`);\n\n watchFiles(source, async (path: string) => {\n log.debug('tcm', `Compiling ${path}`);\n await generateDefinitions(path);\n });\n\n /* istanbul ignore next: not executed in test environment */\n if (process.env.NODE_ENV !== 'test') {\n await new Promise<void>(() => {});\n }\n}\n\nfunction watchFiles(source: string, callback: (path: string) => Promise<void>) {\n const stylesRegex = new RegExp(`\\\\.module\\\\.(${styleExtensions.join('|')})$`);\n const watcher = chokidar.watch(source, {\n ignored: (path, stats) => !!stats?.isFile() && !stylesRegex.test(path),\n ignoreInitial: true,\n });\n watcher.on('add', callback);\n watcher.on('change', callback);\n}\n"],"names":["tcm","compile","filePath","endsWith","compileLess","compileSass","watch","source","getFolders","replace","filesPattern","styleExtensions","join","creator","DtsCreator","camelCase","namedExports","generateDefinitions","file","css","content","create","writeFile","error","log","String","info","files","glob","Promise","all","map","watchFiles","path","debug","process","env","NODE_ENV","callback","stylesRegex","RegExp","watcher","chokidar","ignored","stats","isFile","test","ignoreInitial","on"],"mappings":";;;;+BAsBsBA;;;eAAAA;;;sBAtBD;iEACA;wEACE;uBAES;6BACJ;6BACA;iCACI;;;;;;AAMhC,eAAeC,QAAQC,QAAgB;IACnC,IAAIA,SAASC,QAAQ,CAAC,UAAU;QAC5B,OAAOC,IAAAA,wBAAW,EAACF;IACvB;IACA,IAAIA,SAASC,QAAQ,CAAC,UAAU;QAC5B,OAAOE,IAAAA,wBAAW,EAACH;IACvB;AACJ;AAEO,eAAeF,IAAI,EAAEM,KAAK,EAAc,GAAG,CAAC,CAAC;IAChD,MAAMC,SAASC,IAAAA,iBAAU,IAAGD,MAAM,CAACE,OAAO,CAAC,OAAO;IAClD,MAAMC,eAAe,GAAGH,OAAO,cAAc,EAAEI,gCAAe,CAACC,IAAI,GAAG,CAAC,CAAC;IACxE,MAAMC,UAAU,IAAIC,wBAAU,CAAC;QAAEC,WAAW;QAAMC,cAAc;IAAK;IAErE,MAAMC,sBAAsB,OAAOC;QAC/B,IAAI;YACA,MAAMC,MAAM,MAAMlB,QAAQiB;YAC1B,MAAME,UAAU,MAAMP,QAAQQ,MAAM,CAACH,MAAMC,KAAK,CAAC,CAACb;YAClD,MAAMc,QAAQE,SAAS;QAC3B,EAAE,OAAOC,OAAO;YACZC,UAAG,CAACD,KAAK,CAACE,OAAOF;QACrB;IACJ;IAEA,IAAI,CAACjB,OAAO;QACRkB,UAAG,CAACE,IAAI,CAAC,CAAC,qBAAqB,EAAEhB,cAAc;QAC/C,MAAMiB,QAAQ,MAAMC,IAAAA,UAAI,EAAClB;QACzB,MAAMmB,QAAQC,GAAG,CAACH,MAAMI,GAAG,CAACd;QAC5B;IACJ;IAEAO,UAAG,CAACE,IAAI,CAAC,CAAC,+BAA+B,EAAEhB,cAAc;IAEzDsB,WAAWzB,QAAQ,OAAO0B;QACtBT,UAAG,CAACU,KAAK,CAAC,OAAO,CAAC,UAAU,EAAED,MAAM;QACpC,MAAMhB,oBAAoBgB;IAC9B;IAEA,0DAA0D,GAC1D,IAAIE,QAAQC,GAAG,CAACC,QAAQ,KAAK,QAAQ;QACjC,MAAM,IAAIR,QAAc,KAAO;IACnC;AACJ;AAEA,SAASG,WAAWzB,MAAc,EAAE+B,QAAyC;IACzE,MAAMC,cAAc,IAAIC,OAAO,CAAC,aAAa,EAAE7B,gCAAe,CAACC,IAAI,CAAC,KAAK,EAAE,CAAC;IAC5E,MAAM6B,UAAUC,iBAAQ,CAACpC,KAAK,CAACC,QAAQ;QACnCoC,SAAS,CAACV,MAAMW,QAAU,CAAC,EAACA,kBAAAA,4BAAAA,MAAOC,MAAM,OAAM,CAACN,YAAYO,IAAI,CAACb;QACjEc,eAAe;IACnB;IACAN,QAAQO,EAAE,CAAC,OAAOV;IAClBG,QAAQO,EAAE,CAAC,UAAUV;AACzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-rules.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/file-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAqBtC,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAmDjD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RuleSetRule } from 'webpack';
|
|
2
|
-
export type StyleRule = RuleSetRule & {
|
|
3
|
-
use: (string | object)[];
|
|
4
|
-
};
|
|
5
|
-
export declare const styleRules: Record<string, StyleRule>;
|
|
6
|
-
export declare const webComponentStyleRules: Record<string, StyleRule>;
|
|
7
|
-
export declare const productionStyleRules: Record<string, StyleRule>;
|
|
8
|
-
//# sourceMappingURL=style-rules.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"style-rules.d.ts","sourceRoot":"","sources":["../../../src/webpack/__mocks__/style-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IAAE,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAEnE,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CA4EhD,CAAC;AAEF,eAAO,MAAM,sBAAsB,2BAMlC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2BAUhC,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Configuration } from 'webpack';
|
|
2
|
-
import { Context, Overrides } from './types';
|
|
3
|
-
type Result = Pick<Configuration, 'cache'> | undefined;
|
|
4
|
-
export declare function cacheConfig(context: Context, _: Overrides): Result;
|
|
5
|
-
export {};
|
|
6
|
-
//# sourceMappingURL=cache-config.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-config.d.ts","sourceRoot":"","sources":["../../../src/webpack/configs/cache-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE7C,KAAK,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;AAEvD,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,GAAG,MAAM,CAiBlE"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "cacheConfig", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return cacheConfig;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _utils = require("../../utils");
|
|
12
|
-
const _utils1 = require("../utils");
|
|
13
|
-
function cacheConfig(context, _) {
|
|
14
|
-
const { embed, isProduction, isWebComponent } = context;
|
|
15
|
-
if (isProduction) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
return (0, _utils1.featureCohort)([
|
|
19
|
-
2,
|
|
20
|
-
5
|
|
21
|
-
], ()=>{
|
|
22
|
-
const packageName = (0, _utils.getPackageName)();
|
|
23
|
-
_utils.log.info('Persistent cache is active');
|
|
24
|
-
return {
|
|
25
|
-
cache: {
|
|
26
|
-
type: 'filesystem',
|
|
27
|
-
name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,
|
|
28
|
-
profile: true
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=cache-config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/configs/cache-config.ts"],"sourcesContent":["import { Configuration } from 'webpack';\nimport { getPackageName, log } from '../../utils';\nimport { featureCohort } from '../utils';\nimport { Context, Overrides } from './types';\n\ntype Result = Pick<Configuration, 'cache'> | undefined;\n\nexport function cacheConfig(context: Context, _: Overrides): Result {\n const { embed, isProduction, isWebComponent } = context;\n if (isProduction) {\n return;\n }\n\n return featureCohort([2, 5], () => {\n const packageName = getPackageName();\n log.info('Persistent cache is active');\n return {\n cache: {\n type: 'filesystem',\n name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,\n profile: true,\n },\n };\n });\n}\n"],"names":["cacheConfig","context","_","embed","isProduction","isWebComponent","featureCohort","packageName","getPackageName","log","info","cache","type","name","profile"],"mappings":";;;;+BAOgBA;;;eAAAA;;;uBANoB;wBACN;AAKvB,SAASA,YAAYC,OAAgB,EAAEC,CAAY;IACtD,MAAM,EAAEC,KAAK,EAAEC,YAAY,EAAEC,cAAc,EAAE,GAAGJ;IAChD,IAAIG,cAAc;QACd;IACJ;IAEA,OAAOE,IAAAA,qBAAa,EAAC;QAAC;QAAG;KAAE,EAAE;QACzB,MAAMC,cAAcC,IAAAA,qBAAc;QAClCC,UAAG,CAACC,IAAI,CAAC;QACT,OAAO;YACHC,OAAO;gBACHC,MAAM;gBACNC,MAAMR,iBAAiB,GAAGE,YAAY,EAAE,EAAEJ,QAAQ,UAAU,QAAQ,GAAGI;gBACvEO,SAAS;YACb;QACJ;IACJ;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"feature-cohort.d.ts","sourceRoot":"","sources":["../../../src/webpack/utils/feature-cohort.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAS7F"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "featureCohort", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return featureCohort;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _username = require("username");
|
|
12
|
-
const _utils = require("../../utils");
|
|
13
|
-
const _hashmod = require("./hash-mod");
|
|
14
|
-
function featureCohort([limit, total], fn) {
|
|
15
|
-
if (limit >= total) {
|
|
16
|
-
_utils.log.warning('featureCohort: feature always active');
|
|
17
|
-
}
|
|
18
|
-
const mod = (0, _hashmod.hashMod)(total);
|
|
19
|
-
var _username1;
|
|
20
|
-
const cohort = mod((_username1 = (0, _username.sync)()) !== null && _username1 !== void 0 ? _username1 : '');
|
|
21
|
-
if (cohort < limit) {
|
|
22
|
-
return fn();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=feature-cohort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/utils/feature-cohort.ts"],"sourcesContent":["import { sync as username } from 'username';\n\nimport { log } from '../../utils';\n\nimport { hashMod } from './hash-mod';\n\n/**\n * Allows to enable feature for part of the auditory based on stable trait (username).\n */\nexport function featureCohort<T>([limit, total]: [number, number], fn: () => T): T | undefined {\n if (limit >= total) {\n log.warning('featureCohort: feature always active');\n }\n const mod = hashMod(total);\n const cohort = mod(username() ?? '');\n if (cohort < limit) {\n return fn();\n }\n}\n"],"names":["featureCohort","limit","total","fn","log","warning","mod","hashMod","username","cohort"],"mappings":";;;;+BASgBA;;;eAAAA;;;0BATiB;uBAEb;yBAEI;AAKjB,SAASA,cAAiB,CAACC,OAAOC,MAAwB,EAAEC,EAAW;IAC1E,IAAIF,SAASC,OAAO;QAChBE,UAAG,CAACC,OAAO,CAAC;IAChB;IACA,MAAMC,MAAMC,IAAAA,gBAAO,EAACL;QACDM;IAAnB,MAAMC,SAASH,IAAIE,CAAAA,aAAAA,IAAAA,cAAQ,iBAARA,wBAAAA,aAAc;IACjC,IAAIC,SAASR,OAAO;QAChB,OAAOE;IACX;AACJ"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
3
|
-
* modded by `buckets`.
|
|
4
|
-
*
|
|
5
|
-
* @param {Number} buckets
|
|
6
|
-
* @return {Function}
|
|
7
|
-
*/
|
|
8
|
-
export declare function hashMod(buckets: number): (string: string) => number;
|
|
9
|
-
//# sourceMappingURL=hash-mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash-mod.d.ts","sourceRoot":"","sources":["../../../src/webpack/utils/hash-mod.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,IAClB,QAAQ,MAAM,YAGlC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* salvaged from https://github.com/segment-boneyard/hash-mod
|
|
3
|
-
* 1. recent code from repo never got into npm registry
|
|
4
|
-
* 2. no types in DefinitelyTyped
|
|
5
|
-
*/ /**
|
|
6
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
7
|
-
* modded by `buckets`.
|
|
8
|
-
*
|
|
9
|
-
* @param {Number} buckets
|
|
10
|
-
* @return {Function}
|
|
11
|
-
*/ "use strict";
|
|
12
|
-
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "hashMod", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function() {
|
|
18
|
-
return hashMod;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
function hashMod(buckets) {
|
|
22
|
-
return function(string) {
|
|
23
|
-
return integerHash(string) % buckets;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Return the integer hash of a `string`.
|
|
28
|
-
*
|
|
29
|
-
* http://stackoverflow.com/questions/2624192/good-hash-function-for-strings
|
|
30
|
-
*
|
|
31
|
-
* @param {String} string
|
|
32
|
-
* @returns {Number}
|
|
33
|
-
*/ function integerHash(string) {
|
|
34
|
-
return (string + '').split('').reduce(function(memo, item) {
|
|
35
|
-
return memo * 31 * item.charCodeAt(0) % 982451653;
|
|
36
|
-
}, 7);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
//# sourceMappingURL=hash-mod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/utils/hash-mod.ts"],"sourcesContent":["/*\n * salvaged from https://github.com/segment-boneyard/hash-mod\n * 1. recent code from repo never got into npm registry\n * 2. no types in DefinitelyTyped\n */\n\n/**\n * Returns a `hashMod` function that will return an integer hash of a string\n * modded by `buckets`.\n *\n * @param {Number} buckets\n * @return {Function}\n */\nexport function hashMod(buckets: number) {\n return function (string: string) {\n return integerHash(string) % buckets;\n };\n}\n\n/**\n * Return the integer hash of a `string`.\n *\n * http://stackoverflow.com/questions/2624192/good-hash-function-for-strings\n *\n * @param {String} string\n * @returns {Number}\n */\nfunction integerHash(string: string) {\n return (string + '').split('').reduce(function (memo, item) {\n return (memo * 31 * item.charCodeAt(0)) % 982451653;\n }, 7);\n}\n"],"names":["hashMod","buckets","string","integerHash","split","reduce","memo","item","charCodeAt"],"mappings":"AAAA;;;;CAIC,GAED;;;;;;CAMC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,QAAQC,OAAe;IACnC,OAAO,SAAUC,MAAc;QAC3B,OAAOC,YAAYD,UAAUD;IACjC;AACJ;AAEA;;;;;;;CAOC,GACD,SAASE,YAAYD,MAAc;IAC/B,OAAO,AAACA,CAAAA,SAAS,EAAC,EAAGE,KAAK,CAAC,IAAIC,MAAM,CAAC,SAAUC,IAAI,EAAEC,IAAI;QACtD,OAAO,AAACD,OAAO,KAAKC,KAAKC,UAAU,CAAC,KAAM;IAC9C,GAAG;AACP"}
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
import chokidar from 'chokidar';
|
|
5
|
-
import fs, { Stats } from 'fs';
|
|
6
|
-
|
|
7
|
-
import { getFolders, log } from '../../../utils';
|
|
8
|
-
import * as sassModule from '../compile-sass';
|
|
9
|
-
|
|
10
|
-
import { styleExtensions } from '../style-extensions';
|
|
11
|
-
import { tcm } from '../tcm';
|
|
12
|
-
|
|
13
|
-
jest.mock('../../../utils', () => ({
|
|
14
|
-
...jest.requireActual('../../../utils'),
|
|
15
|
-
getFolders: jest.fn(),
|
|
16
|
-
log: { debug: jest.fn(), error: jest.fn(), info: jest.fn() }, // suppress test output
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Note: These tests don't use memfs because the typed-css-modules package
|
|
21
|
-
* uses node: URLs to import the fs modules, which bypasses the memfs filesystem
|
|
22
|
-
* (as of memfs ~4.6.0).
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
describe('[startup] Cli Utils', () => {
|
|
26
|
-
const source = fs.mkdtempSync('src');
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
jest.resetAllMocks();
|
|
30
|
-
jest.mocked(getFolders).mockReturnValue({ source, destination: 'dist' });
|
|
31
|
-
fs.readdirSync(source).forEach(file => fs.rmSync(`${source}/${file}`));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
afterAll(() => fs.rmSync(source, { recursive: true }));
|
|
35
|
-
|
|
36
|
-
function mockStylesModule(module: string, id = 'foo') {
|
|
37
|
-
const content = `.${id} { display: none; }`;
|
|
38
|
-
fs.writeFileSync(`${source}/${module}`, content);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function expectTypeDefinitions(module: string, id = 'foo') {
|
|
42
|
-
expect(fs.readFileSync(`${source}/${module}.d.ts`, 'utf8')).toContain(
|
|
43
|
-
`export const ${id}: string;`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe(`${tcm.name}`, () => {
|
|
48
|
-
const subject = async () => tcm(options);
|
|
49
|
-
let options: Parameters<typeof tcm>[0];
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
options = undefined;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe.each(styleExtensions)('with %s module', extension => {
|
|
56
|
-
const module = `foo.module.${extension}`;
|
|
57
|
-
|
|
58
|
-
beforeEach(() => mockStylesModule(module));
|
|
59
|
-
|
|
60
|
-
test(`generates Typescript definitions for ${extension} module`, async () => {
|
|
61
|
-
await subject();
|
|
62
|
-
|
|
63
|
-
expectTypeDefinitions(module);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('when an error occurs', () => {
|
|
68
|
-
beforeEach(() => {
|
|
69
|
-
mockStylesModule('foo.module.scss');
|
|
70
|
-
jest.spyOn(sassModule, 'compileSass').mockImplementation(() => {
|
|
71
|
-
throw new Error('Oops!');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('logs error', async () => {
|
|
76
|
-
await subject();
|
|
77
|
-
|
|
78
|
-
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('Oops!'));
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe(`watch mode`, () => {
|
|
83
|
-
type Listener = (path: string) => Promise<void>;
|
|
84
|
-
let watchSpy: jest.SpyInstance;
|
|
85
|
-
let fsWatcher: Partial<ReturnType<typeof chokidar.watch>>;
|
|
86
|
-
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
options = { watch: true };
|
|
89
|
-
fsWatcher = { on: jest.fn() };
|
|
90
|
-
watchSpy = jest.spyOn(chokidar, 'watch').mockReturnValue(fsWatcher as any);
|
|
91
|
-
fs.writeFileSync(`${source}/foo.bar`, '');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('watches for new and changed style modules', async () => {
|
|
95
|
-
await subject();
|
|
96
|
-
|
|
97
|
-
expect(watchSpy).toHaveBeenCalledWith(source, {
|
|
98
|
-
ignored: expect.any(Function),
|
|
99
|
-
ignoreInitial: true,
|
|
100
|
-
});
|
|
101
|
-
expect(fsWatcher.on).toHaveBeenCalledWith('add', expect.any(Function));
|
|
102
|
-
expect(fsWatcher.on).toHaveBeenCalledWith('change', expect.any(Function));
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
function getListener(name: string) {
|
|
106
|
-
const { calls } = jest.mocked(fsWatcher.on)!.mock;
|
|
107
|
-
return calls.find(([event]) => event === name)![1] as Listener;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
describe('"ignored" filter', () => {
|
|
111
|
-
const styleExtensions = ['.module.css', '.module.scss', '.module.less'];
|
|
112
|
-
let ignored: (path: string, stats?: Partial<Stats>) => boolean;
|
|
113
|
-
let filePath: string;
|
|
114
|
-
let stats: Partial<Stats> | undefined;
|
|
115
|
-
|
|
116
|
-
beforeEach(async () => {
|
|
117
|
-
await tcm(options);
|
|
118
|
-
const { calls } = watchSpy.mock;
|
|
119
|
-
ignored = calls[0][1].ignored;
|
|
120
|
-
stats = { isFile: () => true };
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const subject = () => ignored(filePath, stats);
|
|
124
|
-
|
|
125
|
-
function itReturns(value: boolean) {
|
|
126
|
-
test(`returns ${value}`, () => expect(subject()).toBe(value));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
describe.each(styleExtensions)('when path ends with %s', ext => {
|
|
130
|
-
beforeEach(() => (filePath = `foo${ext}`));
|
|
131
|
-
|
|
132
|
-
itReturns(false);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe.each(styleExtensions)('when path contains %s', ext => {
|
|
136
|
-
beforeEach(() => (filePath = `foo${ext}.d.ts`));
|
|
137
|
-
|
|
138
|
-
itReturns(true);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe.each(['', '.scss', '.tsx'])('when path ends with "%s"', ext => {
|
|
142
|
-
beforeEach(() => (filePath = `foo${ext}`));
|
|
143
|
-
|
|
144
|
-
itReturns(true);
|
|
145
|
-
|
|
146
|
-
describe('when stats is undefined', () => {
|
|
147
|
-
beforeEach(() => (stats = undefined));
|
|
148
|
-
|
|
149
|
-
itReturns(false);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('when stats.isFile returns false', () => {
|
|
153
|
-
beforeEach(() => (stats = { isFile: () => false }));
|
|
154
|
-
|
|
155
|
-
itReturns(false);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe('when module is added', () => {
|
|
161
|
-
const module = 'bar.module.scss';
|
|
162
|
-
|
|
163
|
-
const setup = async () => {
|
|
164
|
-
await subject();
|
|
165
|
-
mockStylesModule(module, 'bar');
|
|
166
|
-
await getListener('add')(`${source}/${module}`);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
test('generates Typescript definitions for new module', async () => {
|
|
170
|
-
await setup();
|
|
171
|
-
|
|
172
|
-
expectTypeDefinitions(module, 'bar');
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('when module is changed', () => {
|
|
177
|
-
const module = 'baz.module.less';
|
|
178
|
-
|
|
179
|
-
const setup = async () => {
|
|
180
|
-
mockStylesModule(module, 'foo');
|
|
181
|
-
await subject();
|
|
182
|
-
|
|
183
|
-
mockStylesModule(module, 'baz');
|
|
184
|
-
await getListener('change')(`${source}/${module}`);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
test('generates Typescript definitions for changed module', async () => {
|
|
188
|
-
await setup();
|
|
189
|
-
|
|
190
|
-
expectTypeDefinitions(module, 'baz');
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const styleExtensions = ['css', 'less', 'scss'];
|
package/src/cli/utils/tcm.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { glob } from 'glob';
|
|
2
|
-
import chokidar from 'chokidar';
|
|
3
|
-
import DtsCreator from 'typed-css-modules';
|
|
4
|
-
|
|
5
|
-
import { getFolders, log } from '../../utils';
|
|
6
|
-
import { compileLess } from './compile-less';
|
|
7
|
-
import { compileSass } from './compile-sass';
|
|
8
|
-
import { styleExtensions } from './style-extensions';
|
|
9
|
-
|
|
10
|
-
interface RunOptions {
|
|
11
|
-
watch?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function compile(filePath: string) {
|
|
15
|
-
if (filePath.endsWith('.less')) {
|
|
16
|
-
return compileLess(filePath);
|
|
17
|
-
}
|
|
18
|
-
if (filePath.endsWith('.scss')) {
|
|
19
|
-
return compileSass(filePath);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function tcm({ watch }: RunOptions = {}) {
|
|
24
|
-
const source = getFolders().source.replace(/\\/g, '/');
|
|
25
|
-
const filesPattern = `${source}/**/*.module.{${styleExtensions.join()}}`;
|
|
26
|
-
const creator = new DtsCreator({ camelCase: true, namedExports: true });
|
|
27
|
-
|
|
28
|
-
const generateDefinitions = async (file: string) => {
|
|
29
|
-
try {
|
|
30
|
-
const css = await compile(file);
|
|
31
|
-
const content = await creator.create(file, css, !!watch);
|
|
32
|
-
await content.writeFile();
|
|
33
|
-
} catch (error) {
|
|
34
|
-
log.error(String(error));
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
if (!watch) {
|
|
39
|
-
log.info(`Generating types for ${filesPattern}`);
|
|
40
|
-
const files = await glob(filesPattern);
|
|
41
|
-
await Promise.all(files.map(generateDefinitions));
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
log.info(`Watching to generate types for ${filesPattern}`);
|
|
46
|
-
|
|
47
|
-
watchFiles(source, async (path: string) => {
|
|
48
|
-
log.debug('tcm', `Compiling ${path}`);
|
|
49
|
-
await generateDefinitions(path);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
/* istanbul ignore next: not executed in test environment */
|
|
53
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
54
|
-
await new Promise<void>(() => {});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function watchFiles(source: string, callback: (path: string) => Promise<void>) {
|
|
59
|
-
const stylesRegex = new RegExp(`\\.module\\.(${styleExtensions.join('|')})$`);
|
|
60
|
-
const watcher = chokidar.watch(source, {
|
|
61
|
-
ignored: (path, stats) => !!stats?.isFile() && !stylesRegex.test(path),
|
|
62
|
-
ignoreInitial: true,
|
|
63
|
-
});
|
|
64
|
-
watcher.on('add', callback);
|
|
65
|
-
watcher.on('change', callback);
|
|
66
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Configuration } from 'webpack';
|
|
2
|
-
import { getPackageName, log } from '../../utils';
|
|
3
|
-
import { featureCohort } from '../utils';
|
|
4
|
-
import { Context, Overrides } from './types';
|
|
5
|
-
|
|
6
|
-
type Result = Pick<Configuration, 'cache'> | undefined;
|
|
7
|
-
|
|
8
|
-
export function cacheConfig(context: Context, _: Overrides): Result {
|
|
9
|
-
const { embed, isProduction, isWebComponent } = context;
|
|
10
|
-
if (isProduction) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return featureCohort([2, 5], () => {
|
|
15
|
-
const packageName = getPackageName();
|
|
16
|
-
log.info('Persistent cache is active');
|
|
17
|
-
return {
|
|
18
|
-
cache: {
|
|
19
|
-
type: 'filesystem',
|
|
20
|
-
name: isWebComponent ? `${packageName}__${embed ? 'light' : 'full'}` : packageName,
|
|
21
|
-
profile: true,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { sync as username } from 'username';
|
|
2
|
-
|
|
3
|
-
import { log } from '../../utils';
|
|
4
|
-
|
|
5
|
-
import { hashMod } from './hash-mod';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Allows to enable feature for part of the auditory based on stable trait (username).
|
|
9
|
-
*/
|
|
10
|
-
export function featureCohort<T>([limit, total]: [number, number], fn: () => T): T | undefined {
|
|
11
|
-
if (limit >= total) {
|
|
12
|
-
log.warning('featureCohort: feature always active');
|
|
13
|
-
}
|
|
14
|
-
const mod = hashMod(total);
|
|
15
|
-
const cohort = mod(username() ?? '');
|
|
16
|
-
if (cohort < limit) {
|
|
17
|
-
return fn();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* salvaged from https://github.com/segment-boneyard/hash-mod
|
|
3
|
-
* 1. recent code from repo never got into npm registry
|
|
4
|
-
* 2. no types in DefinitelyTyped
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns a `hashMod` function that will return an integer hash of a string
|
|
9
|
-
* modded by `buckets`.
|
|
10
|
-
*
|
|
11
|
-
* @param {Number} buckets
|
|
12
|
-
* @return {Function}
|
|
13
|
-
*/
|
|
14
|
-
export function hashMod(buckets: number) {
|
|
15
|
-
return function (string: string) {
|
|
16
|
-
return integerHash(string) % buckets;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Return the integer hash of a `string`.
|
|
22
|
-
*
|
|
23
|
-
* http://stackoverflow.com/questions/2624192/good-hash-function-for-strings
|
|
24
|
-
*
|
|
25
|
-
* @param {String} string
|
|
26
|
-
* @returns {Number}
|
|
27
|
-
*/
|
|
28
|
-
function integerHash(string: string) {
|
|
29
|
-
return (string + '').split('').reduce(function (memo, item) {
|
|
30
|
-
return (memo * 31 * item.charCodeAt(0)) % 982451653;
|
|
31
|
-
}, 7);
|
|
32
|
-
}
|