@servicetitan/startup 16.0.2 → 17.1.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/dist/cli/commands/build.js +2 -2
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/bundle-package.js +3 -3
- package/dist/cli/commands/bundle-package.js.map +1 -1
- package/dist/cli/commands/lint.js +4 -4
- package/dist/cli/commands/lint.js.map +1 -1
- package/dist/cli/commands/prepare-package.js +3 -3
- package/dist/cli/commands/prepare-package.js.map +1 -1
- package/dist/cli/commands/start.js +3 -3
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/tests.js +5 -5
- package/dist/cli/commands/tests.js.map +1 -1
- package/dist/cli/utils/assets-copy.js +2 -2
- package/dist/cli/utils/assets-copy.js.map +1 -1
- package/dist/cli/utils/bundle.js +13 -13
- package/dist/cli/utils/bundle.js.map +1 -1
- package/dist/cli/utils/get-module-type.js +1 -1
- package/dist/cli/utils/get-module-type.js.map +1 -1
- package/dist/cli/utils/styles-copy.js +2 -2
- package/dist/cli/utils/styles-copy.js.map +1 -1
- package/dist/cli/utils/tcm.js +4 -4
- package/dist/cli/utils/tcm.js.map +1 -1
- package/dist/cli/utils/tsc.js +2 -2
- package/dist/cli/utils/tsc.js.map +1 -1
- package/dist/utils/get-configuration.js +1 -1
- package/dist/utils/get-configuration.js.map +1 -1
- package/dist/utils/get-destination-folders.js +2 -2
- package/dist/utils/get-destination-folders.js.map +1 -1
- package/dist/utils/get-folders.js +1 -1
- package/dist/utils/get-folders.js.map +1 -1
- package/dist/utils/get-package-name.js +1 -1
- package/dist/utils/get-package-name.js.map +1 -1
- package/dist/utils/get-packages.js +6 -6
- package/dist/utils/get-packages.js.map +1 -1
- package/dist/utils/log.js +3 -3
- package/dist/utils/log.js.map +1 -1
- package/dist/webpack/development.config.js +17 -17
- package/dist/webpack/development.config.js.map +1 -1
- package/dist/webpack/index.js +2 -2
- package/dist/webpack/index.js.map +1 -1
- package/dist/webpack/loaders/expose-loader/index.d.ts +7 -0
- package/dist/webpack/loaders/expose-loader/index.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/index.js +101 -0
- package/dist/webpack/loaders/expose-loader/index.js.map +1 -0
- package/dist/webpack/loaders/expose-loader/runtime/get-global-this.d.ts +1 -0
- package/dist/webpack/loaders/expose-loader/runtime/get-global-this.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/runtime/get-global-this.js +29 -0
- package/dist/webpack/loaders/expose-loader/runtime/get-global-this.js.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/contextify-request.d.ts +2 -0
- package/dist/webpack/loaders/expose-loader/utils/contextify-request.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/contextify-request.js +30 -0
- package/dist/webpack/loaders/expose-loader/utils/contextify-request.js.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/get-new-user-request.d.ts +2 -0
- package/dist/webpack/loaders/expose-loader/utils/get-new-user-request.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/get-new-user-request.js +19 -0
- package/dist/webpack/loaders/expose-loader/utils/get-new-user-request.js.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/index.d.ts +4 -0
- package/dist/webpack/loaders/expose-loader/utils/index.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/index.js +16 -0
- package/dist/webpack/loaders/expose-loader/utils/index.js.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/stringify-request.d.ts +2 -0
- package/dist/webpack/loaders/expose-loader/utils/stringify-request.d.ts.map +1 -0
- package/dist/webpack/loaders/expose-loader/utils/stringify-request.js +27 -0
- package/dist/webpack/loaders/expose-loader/utils/stringify-request.js.map +1 -0
- package/dist/webpack/production.config.js +6 -6
- package/dist/webpack/production.config.js.map +1 -1
- package/dist/webpack/shared.config.js +17 -17
- package/dist/webpack/shared.config.js.map +1 -1
- package/dist/webpack/utils/testing/compile.d.ts +3 -0
- package/dist/webpack/utils/testing/compile.d.ts.map +1 -0
- package/dist/webpack/utils/testing/compile.js +15 -0
- package/dist/webpack/utils/testing/compile.js.map +1 -0
- package/dist/webpack/utils/testing/execute.d.ts +5 -0
- package/dist/webpack/utils/testing/execute.d.ts.map +1 -0
- package/dist/webpack/utils/testing/execute.js +21 -0
- package/dist/webpack/utils/testing/execute.js.map +1 -0
- package/dist/webpack/utils/testing/get-compiler.d.ts +3 -0
- package/dist/webpack/utils/testing/get-compiler.d.ts.map +1 -0
- package/dist/webpack/utils/testing/get-compiler.js +44 -0
- package/dist/webpack/utils/testing/get-compiler.js.map +1 -0
- package/dist/webpack/utils/testing/get-errors.d.ts +3 -0
- package/dist/webpack/utils/testing/get-errors.d.ts.map +1 -0
- package/dist/webpack/utils/testing/get-errors.js +9 -0
- package/dist/webpack/utils/testing/get-errors.js.map +1 -0
- package/dist/webpack/utils/testing/get-module-source.d.ts +4 -0
- package/dist/webpack/utils/testing/get-module-source.d.ts.map +1 -0
- package/dist/webpack/utils/testing/get-module-source.js +13 -0
- package/dist/webpack/utils/testing/get-module-source.js.map +1 -0
- package/dist/webpack/utils/testing/get-warnings.d.ts +3 -0
- package/dist/webpack/utils/testing/get-warnings.d.ts.map +1 -0
- package/dist/webpack/utils/testing/get-warnings.js +9 -0
- package/dist/webpack/utils/testing/get-warnings.js.map +1 -0
- package/dist/webpack/utils/testing/index.d.ts +22 -0
- package/dist/webpack/utils/testing/index.d.ts.map +1 -0
- package/dist/webpack/utils/testing/index.js +27 -0
- package/dist/webpack/utils/testing/index.js.map +1 -0
- package/dist/webpack/utils/testing/normalize-errors.d.ts +3 -0
- package/dist/webpack/utils/testing/normalize-errors.d.ts.map +1 -0
- package/dist/webpack/utils/testing/normalize-errors.js +18 -0
- package/dist/webpack/utils/testing/normalize-errors.js.map +1 -0
- package/dist/webpack/utils/testing/read-asset.d.ts +3 -0
- package/dist/webpack/utils/testing/read-asset.d.ts.map +1 -0
- package/dist/webpack/utils/testing/read-asset.js +27 -0
- package/dist/webpack/utils/testing/read-asset.js.map +1 -0
- package/dist/webpack/utils/testing/read-assets.d.ts +3 -0
- package/dist/webpack/utils/testing/read-assets.d.ts.map +1 -0
- package/dist/webpack/utils/testing/read-assets.js +13 -0
- package/dist/webpack/utils/testing/read-assets.js.map +1 -0
- package/package.json +10 -10
- package/src/cli/utils/tcm.ts +1 -1
- package/src/utils/log.ts +3 -3
- package/src/webpack/loaders/expose-loader/__tests__/__mocks__/configuration.expose-loader.js +13 -0
- package/src/webpack/loaders/expose-loader/__tests__/__mocks__/index.js +1 -0
- package/src/webpack/loaders/expose-loader/__tests__/__snapshots__/index.test.ts.snap +134 -0
- package/src/webpack/loaders/expose-loader/__tests__/index.test.ts +99 -0
- package/src/webpack/loaders/expose-loader/index.ts +124 -0
- package/src/webpack/loaders/expose-loader/runtime/get-global-this.ts +31 -0
- package/src/webpack/loaders/expose-loader/utils/contextify-request.ts +28 -0
- package/src/webpack/loaders/expose-loader/utils/get-new-user-request.ts +15 -0
- package/src/webpack/loaders/expose-loader/utils/index.ts +3 -0
- package/src/webpack/loaders/expose-loader/utils/stringify-request.ts +26 -0
- package/src/webpack/shared.config.ts +2 -2
- package/src/webpack/utils/testing/compile.ts +13 -0
- package/src/webpack/utils/testing/execute.ts +21 -0
- package/src/webpack/utils/testing/get-compiler.ts +45 -0
- package/src/webpack/utils/testing/get-errors.ts +7 -0
- package/src/webpack/utils/testing/get-module-source.ts +11 -0
- package/src/webpack/utils/testing/get-warnings.ts +7 -0
- package/src/webpack/utils/testing/index.ts +23 -0
- package/src/webpack/utils/testing/normalize-errors.ts +18 -0
- package/src/webpack/utils/testing/read-asset.ts +26 -0
- package/src/webpack/utils/testing/read-assets.ts +13 -0
- package/template/package.json +1 -1
- package/template/packages/application/package.json +4 -4
- package/template/packages/application/src/app.css +1 -1
- package/template/packages/application/src/app.tsx +1 -1
- package/template/packages/application/tsconfig.json +2 -0
- package/template/packages/feature-a/package.json +1 -1
- package/template/packages/feature-b/package.json +1 -1
- package/template/packages/feature-c/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`expose-loader should work for a nested property for a global object: errors 1`] = `Array []`;
|
|
4
|
+
|
|
5
|
+
exports[`expose-loader should work for a nested property for a global object: module 1`] = `
|
|
6
|
+
"var ___EXPOSE_LOADER_IMPORT___ = require(\\"-!./configuration.expose-loader.js\\");
|
|
7
|
+
var ___EXPOSE_LOADER_GLOBAL_THIS___ = require(\\"../../runtime/get-global-this.ts\\");
|
|
8
|
+
var ___EXPOSE_LOADER_STORAGE_KEY___ = Symbol.for('SERVICETITAN_EXPOSE_LOADER_STORAGE');
|
|
9
|
+
if (___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] === undefined) {
|
|
10
|
+
___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] = Object.assign(
|
|
11
|
+
Object.create(null),
|
|
12
|
+
{
|
|
13
|
+
clear(scope) {
|
|
14
|
+
delete this[scope];
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
var ___EXPOSE_LOADER_STORAGE___ = ___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___];
|
|
20
|
+
if (___EXPOSE_LOADER_GLOBAL_THIS___['SharedDependencies'] === undefined) {
|
|
21
|
+
___EXPOSE_LOADER_GLOBAL_THIS___['SharedDependencies'] = Object.create(null);
|
|
22
|
+
}
|
|
23
|
+
___EXPOSE_LOADER_GLOBAL_THIS___.SharedDependencies.Configuration = new Proxy(
|
|
24
|
+
Object.assign(Object.create(null), {
|
|
25
|
+
getStorage() {
|
|
26
|
+
return ___EXPOSE_LOADER_STORAGE___;
|
|
27
|
+
},
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
get: function (target, prop, receiver) {
|
|
31
|
+
function getModule(id) {
|
|
32
|
+
if (___EXPOSE_LOADER_STORAGE___[prop] === undefined) {
|
|
33
|
+
___EXPOSE_LOADER_STORAGE___[prop] = Object.create(null);
|
|
34
|
+
}
|
|
35
|
+
if (___EXPOSE_LOADER_STORAGE___[prop][id] !== undefined) {
|
|
36
|
+
return ___EXPOSE_LOADER_STORAGE___[prop][id].exports;
|
|
37
|
+
}
|
|
38
|
+
var module = (___EXPOSE_LOADER_STORAGE___[prop][id] = {
|
|
39
|
+
id,
|
|
40
|
+
loaded: false,
|
|
41
|
+
exports: Object.create(null),
|
|
42
|
+
});
|
|
43
|
+
__webpack_modules__[id].call(module.exports, module, module.exports, getModule);
|
|
44
|
+
module.loaded = true;
|
|
45
|
+
return module.exports;
|
|
46
|
+
}
|
|
47
|
+
Object.setPrototypeOf(getModule, __webpack_require__);
|
|
48
|
+
if (prop === 'getStorage') {
|
|
49
|
+
return Reflect.get(target, prop, receiver);
|
|
50
|
+
}
|
|
51
|
+
return getModule(require.resolveWeak(\\"-!./configuration.expose-loader.js\\"))
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
module.exports = ___EXPOSE_LOADER_IMPORT___;
|
|
56
|
+
"
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
exports[`expose-loader should work for a nested property for a global object: result 1`] = `
|
|
60
|
+
Object {
|
|
61
|
+
"configuration": Object {
|
|
62
|
+
"get": [Function],
|
|
63
|
+
"set": [Function],
|
|
64
|
+
"version": "1.0.0",
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
exports[`expose-loader should work for a nested property for a global object: warnings 1`] = `Array []`;
|
|
70
|
+
|
|
71
|
+
exports[`expose-loader should work: errors 1`] = `Array []`;
|
|
72
|
+
|
|
73
|
+
exports[`expose-loader should work: module 1`] = `
|
|
74
|
+
"var ___EXPOSE_LOADER_IMPORT___ = require(\\"-!./configuration.expose-loader.js\\");
|
|
75
|
+
var ___EXPOSE_LOADER_GLOBAL_THIS___ = require(\\"../../runtime/get-global-this.ts\\");
|
|
76
|
+
var ___EXPOSE_LOADER_STORAGE_KEY___ = Symbol.for('SERVICETITAN_EXPOSE_LOADER_STORAGE');
|
|
77
|
+
if (___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] === undefined) {
|
|
78
|
+
___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] = Object.assign(
|
|
79
|
+
Object.create(null),
|
|
80
|
+
{
|
|
81
|
+
clear(scope) {
|
|
82
|
+
delete this[scope];
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
var ___EXPOSE_LOADER_STORAGE___ = ___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___];
|
|
88
|
+
___EXPOSE_LOADER_GLOBAL_THIS___.Configuration = new Proxy(
|
|
89
|
+
Object.assign(Object.create(null), {
|
|
90
|
+
getStorage() {
|
|
91
|
+
return ___EXPOSE_LOADER_STORAGE___;
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
{
|
|
95
|
+
get: function (target, prop, receiver) {
|
|
96
|
+
function getModule(id) {
|
|
97
|
+
if (___EXPOSE_LOADER_STORAGE___[prop] === undefined) {
|
|
98
|
+
___EXPOSE_LOADER_STORAGE___[prop] = Object.create(null);
|
|
99
|
+
}
|
|
100
|
+
if (___EXPOSE_LOADER_STORAGE___[prop][id] !== undefined) {
|
|
101
|
+
return ___EXPOSE_LOADER_STORAGE___[prop][id].exports;
|
|
102
|
+
}
|
|
103
|
+
var module = (___EXPOSE_LOADER_STORAGE___[prop][id] = {
|
|
104
|
+
id,
|
|
105
|
+
loaded: false,
|
|
106
|
+
exports: Object.create(null),
|
|
107
|
+
});
|
|
108
|
+
__webpack_modules__[id].call(module.exports, module, module.exports, getModule);
|
|
109
|
+
module.loaded = true;
|
|
110
|
+
return module.exports;
|
|
111
|
+
}
|
|
112
|
+
Object.setPrototypeOf(getModule, __webpack_require__);
|
|
113
|
+
if (prop === 'getStorage') {
|
|
114
|
+
return Reflect.get(target, prop, receiver);
|
|
115
|
+
}
|
|
116
|
+
return getModule(require.resolveWeak(\\"-!./configuration.expose-loader.js\\"))
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
module.exports = ___EXPOSE_LOADER_IMPORT___;
|
|
121
|
+
"
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
exports[`expose-loader should work: result 1`] = `
|
|
125
|
+
Object {
|
|
126
|
+
"configuration": Object {
|
|
127
|
+
"get": [Function],
|
|
128
|
+
"set": [Function],
|
|
129
|
+
"version": "1.0.0",
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
exports[`expose-loader should work: warnings 1`] = `Array []`;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
import { Stats } from 'webpack';
|
|
8
|
+
|
|
9
|
+
import { getUtils } from '../../../utils/testing';
|
|
10
|
+
|
|
11
|
+
const { compile, execute, getCompiler, getErrors, getModuleSource, getWarnings, readAsset } =
|
|
12
|
+
getUtils(path.join(__dirname, '../'));
|
|
13
|
+
|
|
14
|
+
function getModulesList(name: string, stats: Stats) {
|
|
15
|
+
const { modules } = stats.toJson({ source: true });
|
|
16
|
+
|
|
17
|
+
if (modules) {
|
|
18
|
+
return modules
|
|
19
|
+
.map(item => item.id)
|
|
20
|
+
.filter(item => (item !== undefined ? String(item).startsWith(name) : false));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
jest.setTimeout(30000);
|
|
27
|
+
|
|
28
|
+
describe('expose-loader', () => {
|
|
29
|
+
it('should work', async () => {
|
|
30
|
+
const compiler = getCompiler('index.js', {
|
|
31
|
+
exposes: 'Configuration',
|
|
32
|
+
});
|
|
33
|
+
const stats = await compile(compiler);
|
|
34
|
+
|
|
35
|
+
expect(getModuleSource('./configuration.expose-loader-exposed.js', stats)).toMatchSnapshot(
|
|
36
|
+
'module'
|
|
37
|
+
);
|
|
38
|
+
expect(
|
|
39
|
+
execute(readAsset('main.bundle.js', compiler, stats), {
|
|
40
|
+
before: '',
|
|
41
|
+
after: 'module.exports = { configuration: Configuration.instance };',
|
|
42
|
+
})
|
|
43
|
+
).toMatchSnapshot('result');
|
|
44
|
+
expect(getErrors(stats)).toMatchSnapshot('errors');
|
|
45
|
+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should work for a nested property for a global object', async () => {
|
|
49
|
+
const compiler = getCompiler('index.js', {
|
|
50
|
+
exposes: 'SharedDependencies.Configuration',
|
|
51
|
+
});
|
|
52
|
+
const stats = await compile(compiler);
|
|
53
|
+
|
|
54
|
+
expect(getModuleSource('./configuration.expose-loader-exposed.js', stats)).toMatchSnapshot(
|
|
55
|
+
'module'
|
|
56
|
+
);
|
|
57
|
+
expect(
|
|
58
|
+
execute(readAsset('main.bundle.js', compiler, stats), {
|
|
59
|
+
before: '',
|
|
60
|
+
after: 'module.exports = { configuration: SharedDependencies.Configuration.instance };',
|
|
61
|
+
})
|
|
62
|
+
).toMatchSnapshot('result');
|
|
63
|
+
expect(getErrors(stats)).toMatchSnapshot('errors');
|
|
64
|
+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should be different modules id', async () => {
|
|
68
|
+
const compiler = getCompiler('index.js', {
|
|
69
|
+
exposes: 'Configuration',
|
|
70
|
+
});
|
|
71
|
+
const stats = await compile(compiler);
|
|
72
|
+
|
|
73
|
+
const modules = getModulesList('./configuration.expose-loader', stats);
|
|
74
|
+
expect(modules[0] !== modules[1]).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should resolve different instances', async () => {
|
|
78
|
+
const compiler = getCompiler('index.js', {
|
|
79
|
+
exposes: 'Configuration',
|
|
80
|
+
});
|
|
81
|
+
const stats = await compile(compiler);
|
|
82
|
+
|
|
83
|
+
const { instance1, instance2 } = execute(readAsset('main.bundle.js', compiler, stats), {
|
|
84
|
+
before: '',
|
|
85
|
+
after: 'module.exports = { instance1: Configuration.instance1, instance2: Configuration.instance2 };',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(instance1.get()).toEqual(instance1.get());
|
|
89
|
+
expect(instance2.get()).toEqual(instance2.get());
|
|
90
|
+
expect(instance1.get()).toEqual(instance2.get());
|
|
91
|
+
|
|
92
|
+
instance1.set({ foo: 'instance1' });
|
|
93
|
+
instance2.set({ foo: 'instance2' });
|
|
94
|
+
|
|
95
|
+
expect(instance1.get()).toEqual(instance1.get());
|
|
96
|
+
expect(instance2.get()).toEqual(instance2.get());
|
|
97
|
+
expect(instance1.get()).not.toEqual(instance2.get());
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { LoaderDefinitionFunction } from 'webpack';
|
|
2
|
+
|
|
3
|
+
import { contextifyRequest, getNewUserRequest, stringifyRequest } from './utils';
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
exposes: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line func-style
|
|
10
|
+
const loader: LoaderDefinitionFunction<Options> = function () {
|
|
11
|
+
const { exposes } = this.getOptions({
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
exposes: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
minLength: 1,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
required: ['exposes'],
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
});
|
|
22
|
+
const callback = this.async();
|
|
23
|
+
|
|
24
|
+
const context = this.context;
|
|
25
|
+
|
|
26
|
+
// Adding `-exposed` suffix for the module with expose-loader preparations.
|
|
27
|
+
if (this._module) {
|
|
28
|
+
this._module.userRequest = getNewUserRequest(this._module.userRequest);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Change the request from an absolute to a relative path, this prevents [chunkhash] values
|
|
33
|
+
* from changing when running webpack builds in different directories.
|
|
34
|
+
*/
|
|
35
|
+
const request = stringifyRequest(
|
|
36
|
+
context,
|
|
37
|
+
`-!${contextifyRequest(context, this.remainingRequest)}`
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
let code = '';
|
|
41
|
+
|
|
42
|
+
code += `var ___EXPOSE_LOADER_IMPORT___ = require(${request});\n`;
|
|
43
|
+
|
|
44
|
+
code += `var ___EXPOSE_LOADER_GLOBAL_THIS___ = require(${stringifyRequest(
|
|
45
|
+
context,
|
|
46
|
+
require.resolve('./runtime/get-global-this')
|
|
47
|
+
)});\n`;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Initialization of the storage for the webpack modules cache.
|
|
51
|
+
* It has the following structure: <storage>.<scope>.<module_id>
|
|
52
|
+
*/
|
|
53
|
+
code += `var ___EXPOSE_LOADER_STORAGE_KEY___ = Symbol.for('SERVICETITAN_EXPOSE_LOADER_STORAGE');\n`;
|
|
54
|
+
code += `if (___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] === undefined) {\n`;
|
|
55
|
+
code += ` ___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___] = Object.assign(\n`;
|
|
56
|
+
code += ` Object.create(null),\n`;
|
|
57
|
+
code += ` {\n`;
|
|
58
|
+
code += ` clear(scope) {\n`;
|
|
59
|
+
code += ` delete this[scope];\n`;
|
|
60
|
+
code += ` },\n`;
|
|
61
|
+
code += ` }\n`;
|
|
62
|
+
code += ` );\n`;
|
|
63
|
+
code += `}\n`;
|
|
64
|
+
code += `var ___EXPOSE_LOADER_STORAGE___ = ___EXPOSE_LOADER_GLOBAL_THIS___[___EXPOSE_LOADER_STORAGE_KEY___];\n`;
|
|
65
|
+
|
|
66
|
+
// Initialization of the path to exposed dependency.
|
|
67
|
+
let path = `___EXPOSE_LOADER_GLOBAL_THIS___`;
|
|
68
|
+
for (const segment of exposes.split('.').slice(0, -1)) {
|
|
69
|
+
path += `['${segment}']`;
|
|
70
|
+
code += `if (${path} === undefined) {\n`;
|
|
71
|
+
code += ` ${path} = Object.create(null);\n`;
|
|
72
|
+
code += `}\n`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Initialization of the exposed dependency variable.
|
|
77
|
+
* It has the following structure: <path>.<dependency_variable>.<scope>
|
|
78
|
+
*/
|
|
79
|
+
code += `___EXPOSE_LOADER_GLOBAL_THIS___.${exposes} = new Proxy(\n`;
|
|
80
|
+
code += ` Object.assign(Object.create(null), {\n`;
|
|
81
|
+
code += ` getStorage() {\n`;
|
|
82
|
+
code += ` return ___EXPOSE_LOADER_STORAGE___;\n`;
|
|
83
|
+
code += ` },\n`;
|
|
84
|
+
code += ` }),\n`;
|
|
85
|
+
code += ` {\n`;
|
|
86
|
+
code += ` get: function (target, prop, receiver) {\n`;
|
|
87
|
+
code += ` function getModule(id) {\n`;
|
|
88
|
+
// The scope initialization in the storage if not been defined yet.
|
|
89
|
+
code += ` if (___EXPOSE_LOADER_STORAGE___[prop] === undefined) {\n`;
|
|
90
|
+
code += ` ___EXPOSE_LOADER_STORAGE___[prop] = Object.create(null);\n`;
|
|
91
|
+
code += ` }\n`;
|
|
92
|
+
// Use module from the cache if already initialized.
|
|
93
|
+
code += ` if (___EXPOSE_LOADER_STORAGE___[prop][id] !== undefined) {\n`;
|
|
94
|
+
code += ` return ___EXPOSE_LOADER_STORAGE___[prop][id].exports;\n`;
|
|
95
|
+
code += ` }\n`;
|
|
96
|
+
// Define the blank for the module.
|
|
97
|
+
code += ` var module = (___EXPOSE_LOADER_STORAGE___[prop][id] = {\n`;
|
|
98
|
+
code += ` id,\n`;
|
|
99
|
+
code += ` loaded: false,\n`;
|
|
100
|
+
code += ` exports: Object.create(null),\n`;
|
|
101
|
+
code += ` });\n`;
|
|
102
|
+
// Load the module and its dependencies.
|
|
103
|
+
code += ` __webpack_modules__[id].call(module.exports, module, module.exports, getModule);\n`;
|
|
104
|
+
code += ` module.loaded = true;\n`;
|
|
105
|
+
code += ` return module.exports;\n`;
|
|
106
|
+
code += ` }\n`;
|
|
107
|
+
// Define additional webpack utilities required for the module loading.
|
|
108
|
+
code += ` Object.setPrototypeOf(getModule, __webpack_require__);\n`;
|
|
109
|
+
// Getting the storage is required for the scope cleaning on customer unmounting.
|
|
110
|
+
code += ` if (prop === 'getStorage') {\n`;
|
|
111
|
+
code += ` return Reflect.get(target, prop, receiver);\n`;
|
|
112
|
+
code += ` }\n`;
|
|
113
|
+
code += ` return getModule(require.resolveWeak(${request}))\n`;
|
|
114
|
+
code += ` },\n`;
|
|
115
|
+
code += ` }\n`;
|
|
116
|
+
code += `);\n`;
|
|
117
|
+
|
|
118
|
+
// Return the regular dependency for the in bundle usage.
|
|
119
|
+
code += `module.exports = ___EXPOSE_LOADER_IMPORT___;\n`;
|
|
120
|
+
|
|
121
|
+
callback(null, code);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export = loader;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
module.exports = (function () {
|
|
4
|
+
if (typeof globalThis === 'object') {
|
|
5
|
+
return globalThis;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let result;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
// This works if eval is allowed (see CSP)
|
|
12
|
+
result = this || new Function('return this')();
|
|
13
|
+
} catch (e) {
|
|
14
|
+
// This works if the window reference is available
|
|
15
|
+
if (typeof window === 'object') {
|
|
16
|
+
return window;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// This works if the self reference is available
|
|
20
|
+
if (typeof self === 'object') {
|
|
21
|
+
return self;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// This works if the global reference is available
|
|
25
|
+
if (typeof global !== 'undefined') {
|
|
26
|
+
return global;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
})();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
export function contextifyRequest(context: string, request: string) {
|
|
4
|
+
return request
|
|
5
|
+
.split('!')
|
|
6
|
+
.map(r => {
|
|
7
|
+
const splitPath = r.split('?');
|
|
8
|
+
|
|
9
|
+
if (/^[a-zA-Z]:\\/.test(splitPath[0])) {
|
|
10
|
+
splitPath[0] = path.win32.relative(context, splitPath[0]);
|
|
11
|
+
|
|
12
|
+
if (!/^[a-zA-Z]:\\/.test(splitPath[0])) {
|
|
13
|
+
splitPath[0] = splitPath[0].replace(/\\/g, '/');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (/^\//.test(splitPath[0])) {
|
|
18
|
+
splitPath[0] = path.posix.relative(context, splitPath[0]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!/^(\.\.\/|\/|[a-zA-Z]:\\)/.test(splitPath[0])) {
|
|
22
|
+
splitPath[0] = `./${splitPath[0]}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return splitPath.join('?');
|
|
26
|
+
})
|
|
27
|
+
.join('!');
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
export function getNewUserRequest(request: string) {
|
|
4
|
+
const splittedRequest = request.split('!');
|
|
5
|
+
const lastPartRequest = splittedRequest.pop()?.split('?', 2) ?? [];
|
|
6
|
+
const pathObject = path.parse(lastPartRequest[0]);
|
|
7
|
+
|
|
8
|
+
pathObject.base = `${path.basename(pathObject.base, pathObject.ext)}-exposed${pathObject.ext}`;
|
|
9
|
+
|
|
10
|
+
lastPartRequest[0] = path.format(pathObject);
|
|
11
|
+
|
|
12
|
+
splittedRequest.push(lastPartRequest.join('?'));
|
|
13
|
+
|
|
14
|
+
return splittedRequest.join('!');
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
export function stringifyRequest(context: string, request: string) {
|
|
4
|
+
const splitted = request.split('!');
|
|
5
|
+
|
|
6
|
+
return JSON.stringify(
|
|
7
|
+
splitted
|
|
8
|
+
.map(part => {
|
|
9
|
+
// First, separate singlePath from query, because the query might contain paths again
|
|
10
|
+
const splittedPart = /^(.*?)(\?.*)/.exec(part);
|
|
11
|
+
const query = splittedPart ? splittedPart[2] : '';
|
|
12
|
+
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
13
|
+
|
|
14
|
+
if (isAbsolutePath(singlePath) && context) {
|
|
15
|
+
singlePath = path.relative(context, singlePath);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return singlePath.replace(/\\/g, '/') + query;
|
|
19
|
+
})
|
|
20
|
+
.join('!')
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function isAbsolutePath(str: string) {
|
|
25
|
+
return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
|
|
26
|
+
}
|
|
@@ -105,7 +105,7 @@ export function createConfig(
|
|
|
105
105
|
...(isExposeSharedDependencies()
|
|
106
106
|
? Object.entries(sharedDependencies).map(([dependency, variable]) => ({
|
|
107
107
|
test: require.resolve(dependency),
|
|
108
|
-
loader: 'expose-loader',
|
|
108
|
+
loader: require.resolve('./loaders/expose-loader'),
|
|
109
109
|
options: {
|
|
110
110
|
exposes: variable,
|
|
111
111
|
},
|
|
@@ -208,7 +208,7 @@ export function createConfig(
|
|
|
208
208
|
externals: Object.entries(sharedDependencies).reduce(
|
|
209
209
|
(result, [dependency, variable]) =>
|
|
210
210
|
Object.assign(result, {
|
|
211
|
-
[dependency]: variable
|
|
211
|
+
[dependency]: `${variable}['${metadata.name}']`,
|
|
212
212
|
}),
|
|
213
213
|
{}
|
|
214
214
|
),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Compiler, Stats } from 'webpack';
|
|
2
|
+
|
|
3
|
+
export function compile(compiler: Compiler) {
|
|
4
|
+
return new Promise<Stats>((resolve, reject) => {
|
|
5
|
+
compiler.run((error, stats) => {
|
|
6
|
+
if (!stats || error) {
|
|
7
|
+
return reject(error);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return resolve(stats);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Module from 'module';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const parentModule = module;
|
|
5
|
+
|
|
6
|
+
export function executeFactory(cwd: string) {
|
|
7
|
+
return function execute(
|
|
8
|
+
code: string,
|
|
9
|
+
{ before, after } = { before: 'const __export__;', after: 'module.exports = __export__;' }
|
|
10
|
+
) {
|
|
11
|
+
const resource = 'test.js';
|
|
12
|
+
const module = new Module(resource, parentModule);
|
|
13
|
+
|
|
14
|
+
module.paths = (Module as any)._nodeModulePaths(path.resolve(cwd, './__tests__/__mocks__'));
|
|
15
|
+
module.filename = resource;
|
|
16
|
+
|
|
17
|
+
(module as any)._compile(`${before}\n${code}\n${after}`, resource);
|
|
18
|
+
|
|
19
|
+
return module.exports;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import webpack, { Configuration } from 'webpack';
|
|
4
|
+
import { merge } from 'webpack-merge';
|
|
5
|
+
|
|
6
|
+
import { createFsFromVolume, Volume } from 'memfs';
|
|
7
|
+
|
|
8
|
+
export function getCompilerFactory(cwd: string) {
|
|
9
|
+
return function getCompiler(entry: string, loaderOptions = {}, config: Configuration = {}) {
|
|
10
|
+
const compiler = webpack(
|
|
11
|
+
merge(
|
|
12
|
+
{
|
|
13
|
+
mode: 'development',
|
|
14
|
+
devtool: config.devtool ?? false,
|
|
15
|
+
context: path.resolve(cwd, './__tests__/__mocks__'),
|
|
16
|
+
entry: path.resolve(cwd, './__tests__/__mocks__', entry),
|
|
17
|
+
output: {
|
|
18
|
+
path: path.resolve(cwd, './__tests__/dist'),
|
|
19
|
+
filename: '[name].bundle.js',
|
|
20
|
+
chunkFilename: '[name].chunk.js',
|
|
21
|
+
},
|
|
22
|
+
module: {
|
|
23
|
+
rules: [
|
|
24
|
+
{
|
|
25
|
+
test: new RegExp(`\\.${path.basename(cwd)}\\.\\w+$`, 'i'),
|
|
26
|
+
rules: [
|
|
27
|
+
{
|
|
28
|
+
loader: require.resolve(cwd),
|
|
29
|
+
options: loaderOptions,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
plugins: [],
|
|
36
|
+
},
|
|
37
|
+
config
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
compiler.outputFileSystem = createFsFromVolume(new Volume());
|
|
42
|
+
|
|
43
|
+
return compiler;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Stats } from 'webpack';
|
|
2
|
+
|
|
3
|
+
export function getModuleSource(name: string, stats: Stats) {
|
|
4
|
+
const { modules } = stats.toJson({ source: true });
|
|
5
|
+
|
|
6
|
+
if (modules) {
|
|
7
|
+
return modules.find(m => m.name?.endsWith(name))?.source;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { compile } from './compile';
|
|
2
|
+
import { executeFactory } from './execute';
|
|
3
|
+
import { getCompilerFactory } from './get-compiler';
|
|
4
|
+
import { getErrors } from './get-errors';
|
|
5
|
+
import { getModuleSource } from './get-module-source';
|
|
6
|
+
import { getWarnings } from './get-warnings';
|
|
7
|
+
import { normalizeErrors } from './normalize-errors';
|
|
8
|
+
import { readAsset } from './read-asset';
|
|
9
|
+
import { readAssets } from './read-assets';
|
|
10
|
+
|
|
11
|
+
export function getUtils(cwd: string) {
|
|
12
|
+
return {
|
|
13
|
+
compile,
|
|
14
|
+
execute: executeFactory(cwd),
|
|
15
|
+
getCompiler: getCompilerFactory(cwd),
|
|
16
|
+
getErrors,
|
|
17
|
+
getModuleSource,
|
|
18
|
+
getWarnings,
|
|
19
|
+
normalizeErrors,
|
|
20
|
+
readAsset,
|
|
21
|
+
readAssets,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WebpackError } from 'webpack';
|
|
2
|
+
|
|
3
|
+
function removeCWD(str: string) {
|
|
4
|
+
const isWin = process.platform === 'win32';
|
|
5
|
+
let cwd = process.cwd();
|
|
6
|
+
|
|
7
|
+
if (isWin) {
|
|
8
|
+
// eslint-disable-next-line no-param-reassign
|
|
9
|
+
str = str.replace(/\\/g, '/');
|
|
10
|
+
cwd = cwd.replace(/\\/g, '/');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return str.replace(new RegExp(cwd, 'g'), '');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function normalizeErrors(errors: WebpackError[]) {
|
|
17
|
+
return errors.map(error => removeCWD(error.toString().split('\n').slice(0, 2).join('\n')));
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import { Compiler, Stats } from 'webpack';
|
|
4
|
+
import { IFs } from 'memfs';
|
|
5
|
+
|
|
6
|
+
export function readAsset(asset: string, compiler: Compiler, stats: Stats) {
|
|
7
|
+
const usedFs = compiler.outputFileSystem as IFs;
|
|
8
|
+
const outputPath = stats.compilation.outputOptions.path ?? '';
|
|
9
|
+
|
|
10
|
+
let data = '';
|
|
11
|
+
let targetFile = asset;
|
|
12
|
+
|
|
13
|
+
const queryStringIdx = targetFile.indexOf('?');
|
|
14
|
+
|
|
15
|
+
if (queryStringIdx >= 0) {
|
|
16
|
+
targetFile = targetFile.substr(0, queryStringIdx);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
data = usedFs.readFileSync(path.join(outputPath, targetFile)).toString();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
data = String(error);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|