@corva/create-app 0.0.0-5fb771a → 0.0.0-62a5f2b

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.
@@ -111,17 +111,16 @@ const finalizeJsBundle = ({ outDir, cssFileNames, appIdentifier, emittedGlobalNa
111
111
  const css = cssFileNames
112
112
  .map(fileName => readFileSync(join(outDir, fileName), 'utf-8'))
113
113
  .join('');
114
- const jsContent = readFileSync(jsPath, 'utf-8');
115
-
116
- writeFileSync(
117
- jsPath,
118
- normalizeIifeGlobalAssignment(
119
- css ? createCssInjection(css) + jsContent : jsContent,
120
- appIdentifier,
121
- emittedGlobalName,
122
- ),
114
+ // normalise first: the fallbacks read the head of the bundle, so a stylesheet
115
+ // sitting in front of it would take the global assignment for itself
116
+ const jsContent = normalizeIifeGlobalAssignment(
117
+ readFileSync(jsPath, 'utf-8'),
118
+ appIdentifier,
119
+ emittedGlobalName,
123
120
  );
124
121
 
122
+ writeFileSync(jsPath, css ? createCssInjection(css) + jsContent : jsContent);
123
+
125
124
  cssFileNames.forEach(fileName => unlinkSync(join(outDir, fileName)));
126
125
  };
127
126
 
@@ -137,6 +136,32 @@ const getCorvaApiEnvVariables = () => {
137
136
  return process.exit(1);
138
137
  };
139
138
 
139
+ // webpack's dev config added this entry point whenever the app depends on
140
+ // mapbox-gl: it reads the access token off @corva/ui and publishes the
141
+ // configured instance as window['mapbox-gl'].
142
+ // A virtual module rather than a direct node_modules URL: mapbox-gl's dist is
143
+ // CJS, so it only imports cleanly once Vite's resolver and dep optimizer see it.
144
+ const MAPBOX_DEV_SETUP_ID = 'virtual:corva-mapbox-dev-setup';
145
+
146
+ const mapboxDevSetupPlugin = () => ({
147
+ name: 'corva-mapbox-dev-setup',
148
+ resolveId(id) {
149
+ return id === MAPBOX_DEV_SETUP_ID ? `\0${MAPBOX_DEV_SETUP_ID}` : null;
150
+ },
151
+ load(id) {
152
+ return id === `\0${MAPBOX_DEV_SETUP_ID}`
153
+ ? "import '@corva/dc-platform-shared/cjs/devcenter/webpack/MapboxGlDevSetupEntryPoint.js';"
154
+ : null;
155
+ },
156
+ transformIndexHtml: () => [
157
+ {
158
+ tag: 'script',
159
+ attrs: { type: 'module', src: `/@id/__x00__${MAPBOX_DEV_SETUP_ID}` },
160
+ injectTo: 'body',
161
+ },
162
+ ],
163
+ });
164
+
140
165
  // The DevCenter dev page edits the app's .env through this endpoint.
141
166
  const dotEnvEndpointPlugin = appDirectory => ({
142
167
  name: 'corva-dotenv-endpoint',
@@ -151,9 +176,22 @@ const dotEnvEndpointPlugin = appDirectory => ({
151
176
 
152
177
  req.on('data', chunk => chunks.push(chunk));
153
178
  req.on('end', () => {
179
+ let update;
180
+
181
+ // webpack's dev server parsed the body with express.json(), which answers
182
+ // 400 on a malformed one; parsing it here would take the server down
183
+ try {
184
+ update = JSON.parse(Buffer.concat(chunks));
185
+ } catch {
186
+ res.statusCode = 400;
187
+ res.end();
188
+
189
+ return;
190
+ }
191
+
154
192
  const currentEnv = existsSync(envPath) ? readFileSync(envPath, 'utf-8') : '';
155
193
 
156
- writeFileSync(envPath, updateDotEnv(currentEnv, JSON.parse(Buffer.concat(chunks))));
194
+ writeFileSync(envPath, updateDotEnv(currentEnv, update));
157
195
  res.statusCode = 200;
158
196
  res.end();
159
197
  });
@@ -182,37 +220,42 @@ export const createViteConfig = ({ pwd }) => {
182
220
  externalPatterns.some(pattern => pattern.test(source));
183
221
 
184
222
  // Package names are not valid JS identifiers, so every global is read off `this`.
223
+ // The name has to match on a package boundary, as isExternal does: matching on a
224
+ // bare prefix maps react-dom/client onto react and emits `this["react"]-dom.client`.
185
225
  const toGlobal = id => {
186
- const staticGlobal = globalDependencies.find(libName => libName === id);
187
-
188
- if (staticGlobal) {
189
- return `this["${staticGlobal}"].default || this["${staticGlobal}"]`;
190
- }
191
-
192
- const dep = globalDependencies.find(libName => id.startsWith(libName));
226
+ const dep = globalDependencies.find(libName => id === libName || id.startsWith(`${libName}/`));
193
227
 
194
228
  if (!dep) {
195
229
  throw new Error(`Unknown dependency: ${id}`);
196
230
  }
197
231
 
198
- return `this["${dep}"]${id.replace(dep, '').replace(/\//g, '.')}`;
232
+ if (dep === id) {
233
+ return `this["${dep}"].default || this["${dep}"]`;
234
+ }
235
+
236
+ return `this["${dep}"]${id.slice(dep.length).replace(/\//g, '.')}`;
199
237
  };
200
238
 
201
239
  const getAlias = () => {
240
+ // jest resolved '~' to src for both templates; keep it in the build too
241
+ const defaultAlias = { '~': resolve(pwd, 'src') };
202
242
  const tsconfigPath = resolve(pwd, 'tsconfig.json');
203
243
 
204
244
  if (!existsSync(tsconfigPath)) {
205
- return {};
245
+ return defaultAlias;
206
246
  }
207
247
 
208
248
  const { compilerOptions } = JSON.parse(readFileSync(tsconfigPath, 'utf-8'));
209
249
 
210
- return Object.fromEntries(
211
- Object.entries(compilerOptions?.paths || {}).map(([key, [value]]) => [
212
- key.replace('/*', ''),
213
- resolve(pwd, value.replace('/*', '')),
214
- ]),
215
- );
250
+ return {
251
+ ...defaultAlias,
252
+ ...Object.fromEntries(
253
+ Object.entries(compilerOptions?.paths || {}).map(([key, [value]]) => [
254
+ key.replace('/*', ''),
255
+ resolve(pwd, value.replace('/*', '')),
256
+ ]),
257
+ ),
258
+ };
216
259
  };
217
260
 
218
261
  return defineConfig(({ command }) => {
@@ -261,6 +304,7 @@ export const createViteConfig = ({ pwd }) => {
261
304
  },
262
305
  plugins: [
263
306
  ...config.plugins,
307
+ ...(packageJson.dependencies?.['mapbox-gl'] ? [mapboxDevSetupPlugin()] : []),
264
308
  viteStaticCopy({
265
309
  watch: { reloadPageOnChange: false },
266
310
  targets: [
@@ -1,3 +1,5 @@
1
+ import { vi } from 'vitest';
2
+
1
3
  import '@testing-library/jest-dom/vitest';
2
4
 
3
5
  class FakeObserver {
@@ -8,8 +10,8 @@ class FakeObserver {
8
10
  disconnect() {}
9
11
  }
10
12
 
11
- globalThis.ResizeObserver = FakeObserver;
12
- globalThis.MutationObserver = FakeObserver;
13
+ vi.stubGlobal('ResizeObserver', FakeObserver);
14
+ vi.stubGlobal('MutationObserver', FakeObserver);
13
15
 
14
16
  // jsdom 22 cannot parse the container queries @corva/ui's components inject, and
15
17
  // reports that straight to stderr on every import. Drop those lines only.
@@ -23,6 +23,8 @@ const uiDependencies = {
23
23
  const jsUiDevDependencies = {
24
24
  '@corva/dc-platform-shared': 'latest',
25
25
  '@corva/eslint-config-browser': '0.2.2',
26
+ // @testing-library/react 16 moved this from a dependency to a peer
27
+ '@testing-library/dom': '10.4.1',
26
28
  '@testing-library/jest-dom': '7.0.1',
27
29
  '@testing-library/react': '16.3.2',
28
30
  '@testing-library/user-event': '14.6.6',
@@ -93,7 +95,7 @@ const uiScripts = {
93
95
  build: 'vite build',
94
96
  start: 'vite --open',
95
97
  zip: 'create-corva-app zip .',
96
- lint: 'eslint --cache ./src/',
98
+ lint: 'eslint --cache --ext .js,.jsx,.ts,.tsx ./src/',
97
99
  release: 'create-corva-app release .',
98
100
  test: 'vitest run',
99
101
  coverage: 'vitest run --coverage',
@@ -110,8 +110,13 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, m
110
110
 
111
111
  itemsToZip.push(
112
112
  'manifest.json',
113
+ // both build systems are listed: missing entries are filtered out in
114
+ // createZipArchive, so one CLI serves webpack apps and Vite apps alike
115
+ 'config-overrides.js',
113
116
  'vite.config.mjs',
114
117
  'index.html',
118
+ 'devApp.js',
119
+ 'isolatedApp.js',
115
120
  'eslint.config.js',
116
121
  'eslint.config.mjs',
117
122
  'tsconfig.json',
@@ -126,6 +131,7 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, m
126
131
  },
127
132
  ...(await transformPatternsIntoFileNames(dirName, ['src/**/*'], options.ignoredFiles)),
128
133
  ...(await transformPatternsIntoFileNames(dirName, ['config/**/*'], options.ignoredFiles)),
134
+ ...(await transformPatternsIntoFileNames(dirName, ['public/**/*'], options.ignoredFiles)),
129
135
  );
130
136
 
131
137
  if (options.appKey) {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@corva/create-app","version":"0.0.0-5fb771a","private":false,"description":"Create an app to use it in CORVA.AI","keywords":["react"],"bugs":{"url":"https://github.com/facebook/create-react-app/issues"},"repository":{"type":"git","url":"https://github.com/corva-ai/create-corva-app"},"license":"MIT","type":"module","bin":{"create-corva-app":"./bin/create-corva-app.cjs"},"files":["bin/**/*.cjs","bin/**/*.js","lib/**/*.js","templates","template_extensions","common"],"scripts":{"build":"echo \"build is not configured for package \\\"×\\\", skipping.\"","get-changelog":"conventional-changelog -r 2 -p angular","lint":"eslint . --resolve-plugins-relative-to $(pwd) --max-warnings 0","lint:fix":"eslint . --fix","release":"git add -A && standard-version -a","release-rc":"npm run release -- --prerelease","run:local-ui-ts-completion":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-completions --appName 'TestAppUiTsCompletions' --segments 'completion' --category 'analytics' --appKey 'corva.testappuitscompletions.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","run:local-ui-ts-drilling":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-drilling --appName 'TestAppUiTsDrilling' --segments 'drilling' --category 'analytics' --appKey 'corva.testappuitsdrilling.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","run:local-ui-ts-intervention":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-intervention --appName 'TestAppUiTsIntervention' --segments 'intervention' --category 'analytics' --appKey 'corva.testappuitsintervention.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","test":"NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"},"lint-staged":{"*.js":"npm run lint:fix"},"resolutions":{"lodash":"4.18.1"},"dependencies":{"archiver":"^5.3.0","chalk":"^4.1.0","commander":"^9.1.0","cross-spawn":"^7.0.3","debug":"^4.3.4","dotenv":"^16.0.0","figlet":"^1.5.0","form-data":"^4.0.0","fs-extra":"^9.0.1","glob":"^8.0.1","got":"^12.5.1","inquirer":"^8.2.3","is-glob":"^4.0.3","lodash":"^4.18.1","npm-api":"^1.0.0","semver":"^7.3.2","terminal-link":"^3.0.0"},"devDependencies":{"@babel/core":"^7.11.0","@babel/eslint-parser":"^7.19.1","@babel/plugin-proposal-class-properties":"^7.18.6","@babel/plugin-syntax-import-assertions":"^7.20.0","@babel/preset-react":"^7.18.6","@commitlint/cli":"^17.3.0","@commitlint/config-conventional":"^17.3.0","@corva/eslint-config-browser":"^0.1.7","@corva/eslint-config-node":"^6.0.0","@corva/node-sdk":"^8.5.0","@types/cross-spawn":"^6.0.2","@types/jest":"^29.5.4","@typescript-eslint/eslint-plugin":"^8.58.1","@typescript-eslint/parser":"^8.58.1","conventional-changelog-cli":"^2.1.0","eslint":"^8.2.0","eslint-config-google":"^0.14.0","eslint-config-prettier":"^8.5.0","eslint-plugin-import":"^2.26.0","eslint-plugin-jest":"^27.1.5","eslint-plugin-jsx-a11y":"^6.7.1","eslint-plugin-prettier":"^4.2.1","eslint-plugin-react":"^7.32.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-require-sort":"^1.3.0","husky":"^8.0.2","jest":"^29.6.4","prettier":"^2.0.0","prettier-plugin-packagejson":"^2.3.0","standard-version":"^9.0.0","typescript":"^5.9.3","zx":"^7.2.3"},"packageManager":"yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71","standard-version":{"skip":{"tag":true}}}
1
+ {"name":"@corva/create-app","version":"0.0.0-62a5f2b","private":false,"description":"Create an app to use it in CORVA.AI","keywords":["react"],"bugs":{"url":"https://github.com/facebook/create-react-app/issues"},"repository":{"type":"git","url":"https://github.com/corva-ai/create-corva-app"},"license":"MIT","type":"module","bin":{"create-corva-app":"./bin/create-corva-app.cjs"},"files":["bin/**/*.cjs","bin/**/*.js","lib/**/*.js","templates","template_extensions","common"],"scripts":{"build":"echo \"build is not configured for package \\\"×\\\", skipping.\"","get-changelog":"conventional-changelog -r 2 -p angular","lint":"eslint . --resolve-plugins-relative-to $(pwd) --max-warnings 0","lint:fix":"eslint . --fix","release":"git add -A && standard-version -a","release-rc":"npm run release -- --prerelease","run:local-ui-ts-completion":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-completions --appName 'TestAppUiTsCompletions' --segments 'completion' --category 'analytics' --appKey 'corva.testappuitscompletions.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","run:local-ui-ts-drilling":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-drilling --appName 'TestAppUiTsDrilling' --segments 'drilling' --category 'analytics' --appKey 'corva.testappuitsdrilling.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","run:local-ui-ts-intervention":"node ./bin/create-corva-app.cjs ../test-app-ui-ts-intervention --appName 'TestAppUiTsIntervention' --segments 'intervention' --category 'analytics' --appKey 'corva.testappuitsintervention.ui' --appType 'ui' --runtime 'ui' -t --extensions corva","test":"NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest"},"lint-staged":{"*.js":"npm run lint:fix"},"resolutions":{"lodash":"4.18.1"},"dependencies":{"archiver":"^5.3.0","chalk":"^4.1.0","commander":"^9.1.0","cross-spawn":"^7.0.3","debug":"^4.3.4","dotenv":"^16.0.0","figlet":"^1.5.0","form-data":"^4.0.0","fs-extra":"^9.0.1","glob":"^8.0.1","got":"^12.5.1","inquirer":"^8.2.3","is-glob":"^4.0.3","lodash":"^4.18.1","npm-api":"^1.0.0","semver":"^7.3.2","terminal-link":"^3.0.0"},"devDependencies":{"@babel/core":"^7.11.0","@babel/eslint-parser":"^7.19.1","@babel/plugin-proposal-class-properties":"^7.18.6","@babel/plugin-syntax-import-assertions":"^7.20.0","@babel/preset-react":"^7.18.6","@commitlint/cli":"^17.3.0","@commitlint/config-conventional":"^17.3.0","@corva/eslint-config-browser":"^0.1.7","@corva/eslint-config-node":"^6.0.0","@corva/node-sdk":"^8.5.0","@types/cross-spawn":"^6.0.2","@types/jest":"^29.5.4","@typescript-eslint/eslint-plugin":"^8.58.1","@typescript-eslint/parser":"^8.58.1","conventional-changelog-cli":"^2.1.0","eslint":"^8.2.0","eslint-config-google":"^0.14.0","eslint-config-prettier":"^8.5.0","eslint-plugin-import":"^2.26.0","eslint-plugin-jest":"^27.1.5","eslint-plugin-jsx-a11y":"^6.7.1","eslint-plugin-prettier":"^4.2.1","eslint-plugin-react":"^7.32.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-require-sort":"^1.3.0","husky":"^8.0.2","jest":"^29.6.4","prettier":"^2.0.0","prettier-plugin-packagejson":"^2.3.0","standard-version":"^9.0.0","typescript":"^5.9.3","zx":"^7.2.3"},"packageManager":"yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71","standard-version":{"skip":{"tag":true}}}
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "root": true,
3
3
  "extends": "@corva/eslint-config-browser",
4
+ "globals": {
5
+ "vi": "readonly"
6
+ },
4
7
  "parserOptions": {
5
8
  "requireConfigFile": false,
6
9
  "babelOptions": {
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "root": true,
3
+ "globals": {
4
+ "vi": "readonly"
5
+ },
3
6
  "parser": "@typescript-eslint/parser",
4
7
  "parserOptions": {
5
8
  "ecmaVersion": 2020,
@@ -320,6 +320,7 @@ yarn start Dev server at http://app.local.corva.ai:8080/
320
320
  yarn build Production bundle
321
321
  yarn test Run tests
322
322
  yarn lint ESLint check
323
+ yarn typecheck Type check (the build does not typecheck)
323
324
  yarn zip Create deployment ZIP
324
325
  yarn release Release to Corva platform
325
326
  ```