@salesforce/pwa-kit-dev 3.0.0 → 3.1.0-preview.1
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/pwa-kit-dev.js
CHANGED
|
@@ -202,7 +202,16 @@ const main = async () => {
|
|
|
202
202
|
)
|
|
203
203
|
.addOption(new program.Option('--noHMR', 'disable the client-side hot module replacement'))
|
|
204
204
|
.action(async ({inspect, noHMR}) => {
|
|
205
|
-
|
|
205
|
+
// We use @babel/node instead of node because we want to support ES6 import syntax
|
|
206
|
+
const babelNode = p.join(
|
|
207
|
+
require.resolve('webpack'),
|
|
208
|
+
'..',
|
|
209
|
+
'..',
|
|
210
|
+
'..',
|
|
211
|
+
'.bin',
|
|
212
|
+
'babel-node'
|
|
213
|
+
)
|
|
214
|
+
execSync(`${babelNode} ${inspect ? '--inspect' : ''} ${resolvedSSRPath}`, {
|
|
206
215
|
env: {
|
|
207
216
|
...process.env,
|
|
208
217
|
...(noHMR ? {HMR: 'false'} : {})
|
|
@@ -62,9 +62,14 @@ class OverridesResolverPlugin {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
|
+
* This takes an import with the overrides dir / extends package removed and finds
|
|
66
|
+
* the corresponding path from overridesFsRead
|
|
65
67
|
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
+
* Ie. Given an import @salesforce/retail-react-app/app/components/header,
|
|
69
|
+
* requestPath is app/components/header
|
|
70
|
+
*
|
|
71
|
+
* @param requestPath - relative import path
|
|
72
|
+
* @param dirs - this._allSearchDirs
|
|
68
73
|
*/
|
|
69
74
|
findFileFromMap(requestPath, dirs) {
|
|
70
75
|
const fileExt = _path.default.extname(requestPath);
|
|
@@ -88,12 +93,38 @@ class OverridesResolverPlugin {
|
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
Given an import request, this function removes the override dir
|
|
99
|
+
or the package name defined in extends.
|
|
100
|
+
For example:
|
|
101
|
+
import * from 'src/configs/webpack/test/overrides/path/data.js resolves to
|
|
102
|
+
path/data.js
|
|
103
|
+
import * from '@salesforce/retail-react-app/app/component/header resolves to
|
|
104
|
+
app/component/header
|
|
105
|
+
TODO: This function is only called if isFromExtends is true. In other words,
|
|
106
|
+
this function is only called if the import request contains a package in extends
|
|
107
|
+
We can probably simplify this function or rename it
|
|
108
|
+
*/
|
|
91
109
|
toOverrideRelative(filepath) {
|
|
92
110
|
const override = this._allSearchDirs.find(dir => {
|
|
93
111
|
return filepath.indexOf(dir) === 0;
|
|
94
112
|
});
|
|
95
113
|
return filepath.substring((override === null || override === void 0 ? void 0 : override.length) + 1);
|
|
96
114
|
}
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
Helper function that returns true only if the import request points to a package in 'extends'
|
|
118
|
+
and the issuer path (the file making the import request) is not located in the overrides dir.
|
|
119
|
+
If true, we re-route the import request to the overrides dir.
|
|
120
|
+
If false, the import request proceeds to the base package in node_modules
|
|
121
|
+
For example, given an import request to a package defined in 'extends'
|
|
122
|
+
(ie. @salesforce/retail-react-app):
|
|
123
|
+
This will return true if the issuer is a file in a base template
|
|
124
|
+
This will return false if the issuer is a file in the overrides dir
|
|
125
|
+
This allow the base template to import from overrides and allows the overrides to import from
|
|
126
|
+
the base template using the same syntax (ie. import from @salesforce/retail-react-app/...)
|
|
127
|
+
*/
|
|
97
128
|
isFromExtends(request, filepath) {
|
|
98
129
|
var _this$extends, _this$extends$, _this$extends$$starts;
|
|
99
130
|
const pkgName = request.split(/(\/|\\)/).filter(item => !item.match(/(\/|\\)/)).slice(0, (_this$extends = this.extends) !== null && _this$extends !== void 0 && (_this$extends$ = _this$extends[0]) !== null && _this$extends$ !== void 0 && (_this$extends$$starts = _this$extends$.startsWith) !== null && _this$extends$$starts !== void 0 && _this$extends$$starts.call(_this$extends$, '@') ? 2 : 1).join('/');
|
|
@@ -11,15 +11,47 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const PROJECT_DIR = `src/configs/webpack/test`;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const EXTENDS_TARGET = '@salesforce/retail-react-app';
|
|
15
|
+
|
|
16
|
+
// Our main webpack config will add the leading '/' if not present in package.json
|
|
17
|
+
// so we can expect the '/' to be present here
|
|
18
|
+
const OVERRIDES_DIR = '/overrides';
|
|
19
|
+
|
|
20
|
+
// Files in this map are the files we expect to see in overrides,
|
|
21
|
+
// reflecting the files found in src/configs/webpack/test/overrides
|
|
22
|
+
// This map takes the form [key, [end, rest]] where given a string /path/file.jsx
|
|
23
|
+
// we split on the last '.' and the former part becomes the key and the latter becomes rest
|
|
24
|
+
// To determine 'end', we split on '/index' and take the latter part of the substring. If the
|
|
25
|
+
// file does not contain '/index' this becomes the filepath from the root of pwa-kit-dev
|
|
26
|
+
const FS_READ_HASHMAP = new Map(Object.entries({
|
|
27
|
+
exists: ['src/configs/webpack/test/overrides/exists.jsx', ['.', 'jsx']],
|
|
28
|
+
newExtension: ['src/configs/webpack/test/overrides/newExtension.tsx', ['.', 'tsx']],
|
|
29
|
+
'path/data': ['src/configs/webpack/test/overrides/path/data.js', ['.', 'js']],
|
|
30
|
+
path: ['/index.jsx', ['index', '.', 'jsx']],
|
|
31
|
+
'path/index.mock': ['/index.mock.jsx', ['.', 'jsx']],
|
|
32
|
+
'path/nested/icon': ['src/configs/webpack/test/overrides/path/nested/icon.svg', ['.', 'svg']]
|
|
33
|
+
}));
|
|
34
|
+
const REWRITE_DIR = PROJECT_DIR + OVERRIDES_DIR;
|
|
17
35
|
const options = {
|
|
18
|
-
overridesDir:
|
|
19
|
-
extends: [
|
|
36
|
+
overridesDir: OVERRIDES_DIR,
|
|
37
|
+
extends: [EXTENDS_TARGET],
|
|
20
38
|
projectDir: PROJECT_DIR
|
|
21
39
|
};
|
|
22
|
-
|
|
40
|
+
|
|
41
|
+
// Helper function. Expects an object with 2 properties: path and request
|
|
42
|
+
const createRequestContextWith = req => {
|
|
43
|
+
return {
|
|
44
|
+
_ResolverCachePluginCacheMiss: true,
|
|
45
|
+
context: {
|
|
46
|
+
// We don't modify or read the issuer in overrides so we can
|
|
47
|
+
// leave this as a constant here
|
|
48
|
+
issuer: 'fake-file.js'
|
|
49
|
+
},
|
|
50
|
+
path: req.path,
|
|
51
|
+
request: req.request
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const setupResolverAndCallback = () => {
|
|
23
55
|
const callback = jest.fn(() => null);
|
|
24
56
|
const resolver = {
|
|
25
57
|
ensureHook: jest.fn(() => null),
|
|
@@ -43,133 +75,315 @@ describe('overrides plugin', () => {
|
|
|
43
75
|
expect(overridesResolver.projectDir).toBe(PROJECT_DIR);
|
|
44
76
|
});
|
|
45
77
|
test('resolver doResolve() hook is called for files in overrides dir', () => {
|
|
78
|
+
// exists.jsx is in FS_READ_HASHMAP
|
|
46
79
|
const REQUEST_PATH = 'exists';
|
|
47
80
|
const REQUEST_EXTENSION = '.jsx';
|
|
48
|
-
const testRequestContext = {
|
|
49
|
-
|
|
50
|
-
context: {
|
|
51
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
52
|
-
},
|
|
53
|
-
path: _path.default.join('./', 'node_modules', EXTENDS_TARGET),
|
|
81
|
+
const testRequestContext = createRequestContextWith({
|
|
82
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
54
83
|
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
55
|
-
};
|
|
84
|
+
});
|
|
56
85
|
const {
|
|
57
86
|
resolver,
|
|
58
87
|
callback
|
|
59
|
-
} = setupResolverAndCallback(
|
|
88
|
+
} = setupResolverAndCallback();
|
|
60
89
|
const overridesResolver = new _overridesPlugin.default(options);
|
|
61
90
|
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
62
|
-
|
|
63
|
-
expect(resolver.ensureHook).toHaveBeenCalled();
|
|
64
|
-
expect(resolver.doResolve).toHaveBeenCalledWith(null, {
|
|
65
|
-
_ResolverCachePluginCacheMiss: true,
|
|
66
|
-
context: {
|
|
67
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
68
|
-
},
|
|
91
|
+
const expectedRequestContext = createRequestContextWith({
|
|
69
92
|
path: _path.default.join(REWRITE_DIR, REQUEST_PATH + REQUEST_EXTENSION),
|
|
70
93
|
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
71
|
-
}
|
|
94
|
+
});
|
|
95
|
+
expect(callback).toHaveBeenCalled();
|
|
96
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, expectedRequestContext, expect.anything(), expect.anything(), expect.anything());
|
|
72
97
|
});
|
|
73
98
|
test('nested and non-ts/tsx/js/jsx files rewrite if in overrides', () => {
|
|
74
99
|
const REQUEST_PATH = `path/nested/icon`;
|
|
75
100
|
const REQUEST_EXTENSION = '.svg';
|
|
76
|
-
const testRequestContext = {
|
|
77
|
-
|
|
78
|
-
context: {
|
|
79
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
80
|
-
},
|
|
81
|
-
path: _path.default.join('./', 'node_modules', EXTENDS_TARGET),
|
|
101
|
+
const testRequestContext = createRequestContextWith({
|
|
102
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
82
103
|
request: `${EXTENDS_TARGET}/${REQUEST_PATH}${REQUEST_EXTENSION}`
|
|
83
|
-
};
|
|
104
|
+
});
|
|
84
105
|
const {
|
|
85
106
|
resolver,
|
|
86
107
|
callback
|
|
87
|
-
} = setupResolverAndCallback(
|
|
108
|
+
} = setupResolverAndCallback();
|
|
88
109
|
const overridesResolver = new _overridesPlugin.default(options);
|
|
89
110
|
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
90
111
|
expect(callback).toHaveBeenCalled();
|
|
91
|
-
expect(resolver.
|
|
92
|
-
expect(resolver.doResolve).toHaveBeenCalledWith(null, {
|
|
93
|
-
_ResolverCachePluginCacheMiss: true,
|
|
94
|
-
context: {
|
|
95
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
96
|
-
},
|
|
112
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
97
113
|
path: _path.default.join(REWRITE_DIR, REQUEST_PATH + REQUEST_EXTENSION),
|
|
98
114
|
request: `${EXTENDS_TARGET}/${REQUEST_PATH}${REQUEST_EXTENSION}`
|
|
99
|
-
}, expect.anything(), expect.anything(), expect.anything());
|
|
115
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
100
116
|
});
|
|
101
117
|
test('resolver doResolve() hook is NOT called for files NOT in overrides dir', () => {
|
|
102
118
|
const REQUEST_PATH = `path/nested/does_not_exist.svg`;
|
|
103
119
|
const REQUEST_EXTENSION = '.svg';
|
|
104
|
-
const testRequestContext = {
|
|
105
|
-
|
|
106
|
-
context: {
|
|
107
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
108
|
-
},
|
|
109
|
-
path: _path.default.join('./', 'node_modules', EXTENDS_TARGET),
|
|
120
|
+
const testRequestContext = createRequestContextWith({
|
|
121
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
110
122
|
request: `${EXTENDS_TARGET}/${REQUEST_PATH}${REQUEST_EXTENSION}`
|
|
111
|
-
};
|
|
123
|
+
});
|
|
112
124
|
const {
|
|
113
125
|
resolver,
|
|
114
126
|
callback
|
|
115
|
-
} = setupResolverAndCallback(
|
|
127
|
+
} = setupResolverAndCallback();
|
|
116
128
|
const overridesResolver = new _overridesPlugin.default(options);
|
|
117
129
|
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
118
130
|
expect(callback).toHaveBeenCalled();
|
|
119
|
-
expect(resolver.ensureHook).not.toHaveBeenCalled();
|
|
120
131
|
expect(resolver.doResolve).not.toHaveBeenCalled();
|
|
121
132
|
});
|
|
122
133
|
test('a file that requests from relative AND base template is able to get both', () => {
|
|
123
134
|
const REQUEST_ONE_PATH = 'exists';
|
|
124
135
|
const REQUEST_ONE_EXTENSION = '.jsx';
|
|
125
|
-
const testOneRequestContext = {
|
|
126
|
-
|
|
127
|
-
context: {
|
|
128
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
129
|
-
},
|
|
130
|
-
path: _path.default.join('./', 'node_modules', EXTENDS_TARGET),
|
|
136
|
+
const testOneRequestContext = createRequestContextWith({
|
|
137
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
131
138
|
request: `${EXTENDS_TARGET}/${REQUEST_ONE_PATH}`
|
|
132
|
-
};
|
|
139
|
+
});
|
|
133
140
|
let {
|
|
134
141
|
resolver,
|
|
135
142
|
callback
|
|
136
|
-
} = setupResolverAndCallback(
|
|
143
|
+
} = setupResolverAndCallback();
|
|
137
144
|
const overridesResolver = new _overridesPlugin.default(options);
|
|
138
145
|
overridesResolver.handleHook(testOneRequestContext, {}, callback, resolver);
|
|
139
146
|
expect(callback).toHaveBeenCalled();
|
|
140
|
-
expect(resolver.
|
|
141
|
-
expect(resolver.doResolve).toHaveBeenCalledWith(null, {
|
|
142
|
-
_ResolverCachePluginCacheMiss: true,
|
|
143
|
-
context: {
|
|
144
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
145
|
-
},
|
|
147
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
146
148
|
path: _path.default.join(REWRITE_DIR, REQUEST_ONE_PATH + REQUEST_ONE_EXTENSION),
|
|
147
|
-
request:
|
|
148
|
-
}, expect.anything(), expect.anything(), expect.anything());
|
|
149
|
-
|
|
150
|
-
// TODO: this might be `..\` on Windows?
|
|
149
|
+
request: `${EXTENDS_TARGET}/exists`
|
|
150
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
151
151
|
const REQUEST_TWO_PATH = `./exists`;
|
|
152
|
-
const testTwoRequestContext = {
|
|
153
|
-
|
|
154
|
-
context: {
|
|
155
|
-
issuer: _path.default.join('./', 'fake-file.js')
|
|
156
|
-
},
|
|
157
|
-
path: _path.default.join('./'),
|
|
152
|
+
const testTwoRequestContext = createRequestContextWith({
|
|
153
|
+
path: './',
|
|
158
154
|
request: REQUEST_TWO_PATH
|
|
159
|
-
};
|
|
155
|
+
});
|
|
160
156
|
({
|
|
161
157
|
resolver,
|
|
162
158
|
callback
|
|
163
|
-
} = setupResolverAndCallback(
|
|
159
|
+
} = setupResolverAndCallback());
|
|
164
160
|
const _overridesResolver = new _overridesPlugin.default(options);
|
|
165
161
|
_overridesResolver.handleHook(testTwoRequestContext, {}, callback, resolver);
|
|
166
162
|
expect(callback).toHaveBeenCalled();
|
|
167
|
-
expect(resolver.ensureHook).not.toHaveBeenCalled();
|
|
168
163
|
expect(resolver.doResolve).not.toHaveBeenCalledWith();
|
|
169
164
|
});
|
|
170
|
-
test('jsx base template files can be replaced by tsx files', () => {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
165
|
+
test('jsx base template files can be replaced by tsx files', () => {
|
|
166
|
+
const REQUEST_PATH = 'newExtension';
|
|
167
|
+
const REQUEST_BASE_EXTENSION = '.jsx';
|
|
168
|
+
const REQUEST_OVERRIDE_EXTENSION = '.tsx';
|
|
169
|
+
const testRequestContext = createRequestContextWith({
|
|
170
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET, REQUEST_PATH, REQUEST_BASE_EXTENSION),
|
|
171
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
172
|
+
});
|
|
173
|
+
let {
|
|
174
|
+
resolver,
|
|
175
|
+
callback
|
|
176
|
+
} = setupResolverAndCallback();
|
|
177
|
+
const overridesResolver = new _overridesPlugin.default(options);
|
|
178
|
+
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
179
|
+
expect(callback).toHaveBeenCalled();
|
|
180
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
181
|
+
path: _path.default.join(REWRITE_DIR, REQUEST_PATH + REQUEST_OVERRIDE_EXTENSION),
|
|
182
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
183
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
184
|
+
});
|
|
185
|
+
test('overridesDir and projectDir are normalized with leading slash and forward slashes', () => {
|
|
186
|
+
// In this test, all inputs use \\ to simulate Windows file paths
|
|
187
|
+
const REQUEST_PATH = 'exists';
|
|
188
|
+
const REQUEST_EXTENSION = '.jsx';
|
|
189
|
+
const testRequestContext = createRequestContextWith({
|
|
190
|
+
path: '.\\node_modules\\' + EXTENDS_TARGET,
|
|
191
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
192
|
+
});
|
|
193
|
+
const {
|
|
194
|
+
resolver,
|
|
195
|
+
callback
|
|
196
|
+
} = setupResolverAndCallback();
|
|
197
|
+
|
|
198
|
+
// NOTE: These options are not valid in package.json as it doesn't accept Windows paths
|
|
199
|
+
// in the outer calling context in configs/webpack/config.js.
|
|
200
|
+
// We have this here as the OverridesResolverPlugin technically allows for this
|
|
201
|
+
// and it lets us test that paths are being normalized
|
|
202
|
+
const windowsOptions = {
|
|
203
|
+
overridesDir: '\\overrides',
|
|
204
|
+
extends: ['@salesforce/retail-react-app'],
|
|
205
|
+
projectDir: `src\\configs\\webpack\\test`
|
|
206
|
+
};
|
|
207
|
+
const overridesResolver = new _overridesPlugin.default(windowsOptions);
|
|
208
|
+
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
209
|
+
expect(callback).toHaveBeenCalled();
|
|
210
|
+
// The assert uses path.join which normalizes '\\' to '/' on non-Windows
|
|
211
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
212
|
+
path: _path.default.join(REWRITE_DIR, REQUEST_PATH + REQUEST_EXTENSION),
|
|
213
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
214
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
215
|
+
});
|
|
216
|
+
test('overrides do not return .mock files', () => {
|
|
217
|
+
// FS_READ_HASHMAP above has both index.jsx and index.mock.jsx
|
|
218
|
+
// This test checks that index.jsx is returned by the override
|
|
219
|
+
const REQUEST_PATH = `path`;
|
|
220
|
+
const testRequestContext = createRequestContextWith({
|
|
221
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
222
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
223
|
+
});
|
|
224
|
+
const {
|
|
225
|
+
resolver,
|
|
226
|
+
callback
|
|
227
|
+
} = setupResolverAndCallback();
|
|
228
|
+
const overridesResolver = new _overridesPlugin.default(options);
|
|
229
|
+
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
230
|
+
expect(callback).toHaveBeenCalled();
|
|
231
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
232
|
+
path: _path.default.join(REWRITE_DIR, REQUEST_PATH, `index.jsx`),
|
|
233
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
234
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
235
|
+
});
|
|
236
|
+
test('a nested overrides folder path/to/overrides resolves correctly', () => {
|
|
237
|
+
const REQUEST_PATH = 'exists';
|
|
238
|
+
const REQUEST_EXTENSION = '.jsx';
|
|
239
|
+
const testRequestContext = createRequestContextWith({
|
|
240
|
+
path: _path.default.join('.', 'node_modules', EXTENDS_TARGET),
|
|
241
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
242
|
+
});
|
|
243
|
+
const {
|
|
244
|
+
resolver,
|
|
245
|
+
callback
|
|
246
|
+
} = setupResolverAndCallback();
|
|
247
|
+
const nestedOverridesOptions = {
|
|
248
|
+
overridesDir: '/path/to/overrides',
|
|
249
|
+
extends: ['@salesforce/retail-react-app'],
|
|
250
|
+
projectDir: PROJECT_DIR
|
|
251
|
+
};
|
|
252
|
+
const overridesResolver = new _overridesPlugin.default(nestedOverridesOptions);
|
|
253
|
+
overridesResolver.handleHook(testRequestContext, {}, callback, resolver);
|
|
254
|
+
const nestedRewriteDir = 'src/configs/webpack/test/path/to/overrides';
|
|
255
|
+
expect(callback).toHaveBeenCalled();
|
|
256
|
+
expect(resolver.doResolve).toHaveBeenCalledWith(null, createRequestContextWith({
|
|
257
|
+
path: _path.default.join(nestedRewriteDir, REQUEST_PATH + REQUEST_EXTENSION),
|
|
258
|
+
request: `${EXTENDS_TARGET}/${REQUEST_PATH}`
|
|
259
|
+
}), expect.anything(), expect.anything(), expect.anything());
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
describe('OverridePlugin.isFromExtends', () => {
|
|
263
|
+
let os;
|
|
264
|
+
let cases;
|
|
265
|
+
if (_path.default.sep === '\\') {
|
|
266
|
+
// WINDOWS test cases
|
|
267
|
+
os = 'windows';
|
|
268
|
+
cases = [{
|
|
269
|
+
name: 'Import from a package in extends',
|
|
270
|
+
request: '@salesforce/retail-react-app/exists',
|
|
271
|
+
filepath: '.\\node_modules\\@salesforce\\retail-react-app',
|
|
272
|
+
result: true
|
|
273
|
+
}, {
|
|
274
|
+
name: 'Import from a package not in extends',
|
|
275
|
+
request: '@salesforce/express-minimal/notExists',
|
|
276
|
+
filepath: '.\\node_modules\\@salesforce\\retail-react-app',
|
|
277
|
+
result: false
|
|
278
|
+
}, {
|
|
279
|
+
name: 'Do not trigger override if filepath of issuer contains overrides directory',
|
|
280
|
+
request: '@salesforce/retail-react-app/exists',
|
|
281
|
+
filepath: 'src\\configs\\webpack\\test\\overrides\\exists',
|
|
282
|
+
result: false
|
|
283
|
+
}];
|
|
284
|
+
} else {
|
|
285
|
+
// POSIX test cases
|
|
286
|
+
os = 'posix';
|
|
287
|
+
cases = [{
|
|
288
|
+
name: 'Import from a package in extends',
|
|
289
|
+
request: '@salesforce/retail-react-app/exists',
|
|
290
|
+
filepath: './node_modules/@salesforce/retail-react-app',
|
|
291
|
+
result: true
|
|
292
|
+
}, {
|
|
293
|
+
name: 'Import from a package not in extends',
|
|
294
|
+
request: '@salesforce/express-minimal/notExists',
|
|
295
|
+
filepath: './node_modules/@salesforce/retail-react-app',
|
|
296
|
+
result: false
|
|
297
|
+
}, {
|
|
298
|
+
name: 'Do not trigger override if filepath of issuer contains overrides directory',
|
|
299
|
+
request: '@salesforce/retail-react-app/exists',
|
|
300
|
+
filepath: 'src/configs/webpack/test/overrides/exists',
|
|
301
|
+
result: false
|
|
302
|
+
}];
|
|
303
|
+
}
|
|
304
|
+
const plugin = new _overridesPlugin.default(options);
|
|
305
|
+
describe('Testing scenarios for: ' + os, () => {
|
|
306
|
+
cases.forEach(testCase =>
|
|
307
|
+
// eslint-disable-next-line jest/valid-title
|
|
308
|
+
test(testCase.name, () => {
|
|
309
|
+
const result = plugin.isFromExtends(testCase.request, testCase.filepath);
|
|
310
|
+
expect(result).toBe(testCase.result);
|
|
311
|
+
}));
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
describe('OverridePlugin.toOverrideRelative', () => {
|
|
315
|
+
const plugin = new _overridesPlugin.default(options);
|
|
316
|
+
|
|
317
|
+
// This is the only valid scenario since we only call this if isFromExtends is true
|
|
318
|
+
test('filepath contains extends package, extends package removed from path', () => {
|
|
319
|
+
const result = plugin.toOverrideRelative('@salesforce/retail-react-app/path/nested/icon');
|
|
320
|
+
console.log(result);
|
|
321
|
+
expect(result).toBe('path/nested/icon');
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
describe('OverridePlugin.findFileFromMap', () => {
|
|
325
|
+
let os;
|
|
326
|
+
let opts = options;
|
|
327
|
+
let cases;
|
|
328
|
+
if (_path.default.sep === '\\') {
|
|
329
|
+
// WINDOWS test cases
|
|
330
|
+
os = 'windows';
|
|
331
|
+
cases = [{
|
|
332
|
+
name: 'request path contains nested path',
|
|
333
|
+
requestPath: 'path/nested/icon',
|
|
334
|
+
expectedResult: 'src\\configs\\webpack\\test\\overrides\\path\\nested\\icon.svg'
|
|
335
|
+
}, {
|
|
336
|
+
name: 'request path does not have file extension finds index file',
|
|
337
|
+
requestPath: 'path',
|
|
338
|
+
expectedResult: 'src\\configs\\webpack\\test\\overrides\\path\\index.jsx'
|
|
339
|
+
}, {
|
|
340
|
+
name: 'non-index file request path contains file extension',
|
|
341
|
+
requestPath: 'path/data.js',
|
|
342
|
+
expectedResult: 'src\\configs\\webpack\\test\\overrides\\path\\data.js'
|
|
343
|
+
}];
|
|
344
|
+
} else {
|
|
345
|
+
// POSIX test cases
|
|
346
|
+
os = 'posix';
|
|
347
|
+
cases = [{
|
|
348
|
+
name: 'request path contains nested path',
|
|
349
|
+
requestPath: 'path/nested/icon',
|
|
350
|
+
expectedResult: 'src/configs/webpack/test/overrides/path/nested/icon.svg'
|
|
351
|
+
}, {
|
|
352
|
+
name: 'request path does not have file extension finds index file',
|
|
353
|
+
requestPath: 'path',
|
|
354
|
+
expectedResult: 'src/configs/webpack/test/overrides/path/index.jsx'
|
|
355
|
+
}, {
|
|
356
|
+
name: 'non-index file request path contains file extension',
|
|
357
|
+
requestPath: 'path/data.js',
|
|
358
|
+
expectedResult: 'src/configs/webpack/test/overrides/path/data.js'
|
|
359
|
+
}];
|
|
360
|
+
}
|
|
361
|
+
const plugin = new _overridesPlugin.default(options);
|
|
362
|
+
describe('Testing scenarios for: ' + os, () => {
|
|
363
|
+
cases.forEach(testCase =>
|
|
364
|
+
// eslint-disable-next-line jest/valid-title
|
|
365
|
+
test(testCase.name, () => {
|
|
366
|
+
const result = plugin.findFileFromMap(testCase.requestPath, plugin._allSearchDirs);
|
|
367
|
+
expect(result).toBe(testCase.expectedResult);
|
|
368
|
+
}));
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// The following test's result is the same regardless of OS
|
|
372
|
+
test('request path does not have file extension or extends dir', () => {
|
|
373
|
+
const result = plugin.findFileFromMap('@salesforce/express-minimal/notExists', plugin._allSearchDirs);
|
|
374
|
+
expect(result).toBeUndefined();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// TODO - Fix this in a future task
|
|
378
|
+
// This reproduces a bug! findFileFromMap treats the .mock as a file extension
|
|
379
|
+
// and the key becomes path/index, which is invalid (not only is path/index the wrong file,
|
|
380
|
+
// this is also the wrong key since we splice on '/index' when making the FS_READ_HASHMAP.
|
|
381
|
+
// the correct key for a path/index.js file is just 'path')
|
|
382
|
+
// This currently returns undefined rather than the path to the .mock file
|
|
383
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
384
|
+
// test('request path contains a '.' ie. index.mock', () => {
|
|
385
|
+
// const result = plugin.findFileFromMap('path/index.mock', plugin._allSearchDirs)
|
|
386
|
+
// console.log(result)
|
|
387
|
+
// expect(result).toBe('src/configs/webpack/test/overrides/path/index.mock.jsx')
|
|
388
|
+
// })
|
|
175
389
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/pwa-kit-dev",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-preview.1",
|
|
4
4
|
"description": "Build tools for pwa-kit",
|
|
5
5
|
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-dev#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@babel/cli": "^7.21.0",
|
|
40
40
|
"@babel/core": "^7.21.3",
|
|
41
41
|
"@babel/eslint-parser": "^7.21.3",
|
|
42
|
+
"@babel/node": "^7.22.5",
|
|
42
43
|
"@babel/parser": "^7.21.3",
|
|
43
44
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
44
45
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"@loadable/server": "^5.15.3",
|
|
58
59
|
"@loadable/webpack-plugin": "^5.15.2",
|
|
59
60
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
60
|
-
"@salesforce/pwa-kit-runtime": "3.0.
|
|
61
|
+
"@salesforce/pwa-kit-runtime": "3.1.0-preview.1",
|
|
61
62
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
62
63
|
"@typescript-eslint/parser": "^5.57.0",
|
|
63
64
|
"archiver": "1.3.0",
|
|
@@ -118,7 +119,7 @@
|
|
|
118
119
|
"@types/node-fetch": "^2.6.3",
|
|
119
120
|
"@types/validator": "^13.7.14",
|
|
120
121
|
"eslint-plugin-no-relative-import-paths": "^1.5.2",
|
|
121
|
-
"internal-lib-build": "3.0.
|
|
122
|
+
"internal-lib-build": "3.1.0-preview.1",
|
|
122
123
|
"nock": "^13.3.0",
|
|
123
124
|
"nodemon": "^2.0.22",
|
|
124
125
|
"superagent": "^6.1.0",
|
|
@@ -147,5 +148,5 @@
|
|
|
147
148
|
"publishConfig": {
|
|
148
149
|
"directory": "dist"
|
|
149
150
|
},
|
|
150
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "20438d3d7fdb933c624860787b24a64bf390e005"
|
|
151
152
|
}
|