sku 14.9.0 → 14.10.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/CHANGELOG.md +32 -1
- package/dist/config/{babel/babelConfig.js → babel.js} +2 -2
- package/dist/{services/eslint/config/index.js → config/eslint/config.js} +1 -1
- package/dist/{services/eslint/config → config/eslint}/importOrder.d.ts +1 -1
- package/dist/config/jest/jsBabelTransform.js +1 -1
- package/dist/config/jest/tsBabelTransform.js +1 -1
- package/dist/config/storybook/{index.cjs → config.cjs} +3 -2
- package/dist/program/commands/init/init.command.js +1 -1
- package/dist/program/commands/translations/helpers/translation-helpers.js +1 -1
- package/dist/services/eslint/eslintMigration.js +1 -1
- package/dist/services/packageManager/packageManager.js +1 -1
- package/dist/services/packageManager/pnpmConfig.js +2 -1
- package/dist/services/prettier/runPrettier.js +1 -1
- package/dist/services/typescript/{config/tsconfig.d.ts → tsconfig.d.ts} +1 -1
- package/dist/services/typescript/{config/tsconfig.js → tsconfig.js} +1 -1
- package/dist/services/vite/helpers/config/baseConfig.js +4 -4
- package/dist/services/vite/helpers/config/createConfig.js +4 -0
- package/dist/services/vite/helpers/config/dependencyGraph.js +19 -6
- package/dist/services/vite/plugins/middlewarePlugin.js +1 -1
- package/dist/services/vite/plugins/setSsrNoExternal.d.ts +1 -1
- package/dist/services/vite/plugins/setSsrNoExternal.js +3 -5
- package/dist/services/vite/plugins/ssrCss/collect.d.ts +2 -0
- package/dist/services/vite/plugins/ssrCss/collect.js +45 -0
- package/dist/services/vite/plugins/ssrCss/index.d.ts +1 -0
- package/dist/services/vite/plugins/ssrCss/index.js +1 -0
- package/dist/services/vite/plugins/ssrCss/plugin.d.ts +11 -0
- package/dist/services/vite/plugins/ssrCss/plugin.js +83 -0
- package/dist/services/vocab/{config/vocab.d.ts → config.d.ts} +1 -1
- package/dist/services/vocab/runVocab.js +1 -1
- package/dist/services/webpack/config/utils/loaders.d.ts +1 -1
- package/dist/services/webpack/config/utils/loaders.js +1 -1
- package/dist/services/webpack/config/webpack.config.js +1 -1
- package/dist/services/webpack/config/webpack.config.ssr.js +2 -1
- package/dist/utils/SkuConfigUpdater.js +1 -1
- package/dist/utils/configureApp.js +2 -2
- package/package.json +6 -6
- /package/dist/config/{babel/babelConfig.d.ts → babel.d.ts} +0 -0
- /package/dist/{services/eslint/config/index.d.ts → config/eslint/config.d.ts} +0 -0
- /package/dist/{services/eslint/config → config/eslint}/ignores.d.ts +0 -0
- /package/dist/{services/eslint/config → config/eslint}/ignores.js +0 -0
- /package/dist/{services/eslint/config → config/eslint}/importOrder.js +0 -0
- /package/dist/config/jest/{jest-preset.d.ts → preset.d.ts} +0 -0
- /package/dist/config/jest/{jest-preset.js → preset.js} +0 -0
- /package/dist/{services/prettier/config/prettierConfig.d.ts → config/prettier.d.ts} +0 -0
- /package/dist/{services/prettier/config/prettierConfig.js → config/prettier.js} +0 -0
- /package/dist/config/storybook/{index.d.cts → config.d.cts} +0 -0
- /package/dist/config/storybook/{storybookWebpackConfig.d.ts → webpackConfig.d.ts} +0 -0
- /package/dist/config/storybook/{storybookWebpackConfig.js → webpackConfig.js} +0 -0
- /package/dist/services/packageManager/{context/packageManager.d.ts → context.d.ts} +0 -0
- /package/dist/services/packageManager/{context/packageManager.js → context.js} +0 -0
- /package/dist/services/vocab/{config/vocab.js → config.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# sku
|
|
2
2
|
|
|
3
|
+
## 14.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add production babel plugins to Vite bundler for optimized builds. ([#1350](https://github.com/seek-oss/sku/pull/1350))
|
|
8
|
+
- `babel-plugin-transform-react-remove-prop-types` - Strips PropTypes from production builds
|
|
9
|
+
- `@babel/plugin-transform-react-constant-elements` - Hoists constant JSX elements
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- `start(vite)`: Fix sporadic hydration issues ([#1356](https://github.com/seek-oss/sku/pull/1356))
|
|
14
|
+
|
|
15
|
+
- Fix hot reload modules loading as ESM causing Reference Error for type: module packages ([#1361](https://github.com/seek-oss/sku/pull/1361))
|
|
16
|
+
|
|
17
|
+
When in type: module package hot-module files (`*.hot-update.js`) could be loaded as ESM.
|
|
18
|
+
Resulting in a reference error.
|
|
19
|
+
|
|
20
|
+
**Example Error:**
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
exports.id = 0;
|
|
24
|
+
^
|
|
25
|
+
// ReferenceError: exports is not defined
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Hot reload modules are now exported as `*.hot-update.cjs` to ensure they are loaded as CJS.
|
|
29
|
+
|
|
30
|
+
- Don't emit `.npmrc` validation warning on CI ([#1352](https://github.com/seek-oss/sku/pull/1352))
|
|
31
|
+
|
|
32
|
+
`.npmrc` files may be generated on CI, causing a false positive
|
|
33
|
+
|
|
3
34
|
## 14.9.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
|
@@ -8,7 +39,7 @@
|
|
|
8
39
|
|
|
9
40
|
### React 19 support
|
|
10
41
|
|
|
11
|
-
Sku now has React 19 support, while still supporting React 18.
|
|
42
|
+
Sku now has React 19 support, while still supporting React 18. **React 19 contains breaking changes**. Please refer to the [React 19 migration guide](https://react.dev/blog/2024/04/25/react-19-upgrade-guide) for more information on how to upgrade your application.
|
|
12
43
|
|
|
13
44
|
### Vite bundler improvements
|
|
14
45
|
- `config`: The vite bundler now has full support for all sku static-site config properties. (library mode and ssr mode is not supported.)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { cwd } from '
|
|
1
|
+
import { cwd } from '../utils/cwd.js';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { rootResolutionFileExtensions } from '
|
|
3
|
+
import { rootResolutionFileExtensions } from './fileResolutionExtensions.js';
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
5
|
export default ({ target, lang = 'js', browserslist, displayNamesProd = false, removeAssertionsInProduction = true, hot = false, rootResolution = false, }) => {
|
|
6
6
|
const isBrowser = target === 'browser';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import eslintConfigSeek from 'eslint-config-seek';
|
|
3
3
|
import { createImportOrderConfig } from './importOrder.js';
|
|
4
4
|
import { createEslintIgnoresConfig } from './ignores.js';
|
|
5
|
-
import { getSkuContext } from '
|
|
5
|
+
import { getSkuContext } from '../../context/createSkuContext.js';
|
|
6
6
|
export const createEslintConfig = ({ configPath, } = {}) => {
|
|
7
7
|
const skuContext = getSkuContext({ configPath });
|
|
8
8
|
const { eslintDecorator, eslintIgnore, languages, paths } = skuContext;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SkuContext } from '
|
|
1
|
+
import type { SkuContext } from '../../context/createSkuContext.js';
|
|
2
2
|
export declare const createImportOrderConfig: ({ paths, rootResolution, }: SkuContext) => {
|
|
3
3
|
rules: {
|
|
4
4
|
'import-x/order': (string | {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createTransformer } from 'babel-jest';
|
|
2
|
-
import babelConfig from '../babel
|
|
2
|
+
import babelConfig from '../babel.js';
|
|
3
3
|
import targets from '../targets.json' with { type: 'json' };
|
|
4
4
|
import { getSkuContext } from '../../context/createSkuContext.js';
|
|
5
5
|
const { rootResolution } = getSkuContext();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createTransformer } from 'babel-jest';
|
|
2
|
-
import babelConfig from '../babel
|
|
2
|
+
import babelConfig from '../babel.js';
|
|
3
3
|
import targets from '../targets.json' with { type: 'json' };
|
|
4
4
|
import { getSkuContext } from '../../context/createSkuContext.js';
|
|
5
5
|
const { rootResolution } = getSkuContext();
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/** @type AsyncWebpackFinal */
|
|
17
17
|
const webpackFinal = async (config, { configType }) => {
|
|
18
|
-
const makeStorybookWebpackConfig = (await import('./
|
|
18
|
+
const makeStorybookWebpackConfig = (await import('./webpackConfig.js'))
|
|
19
|
+
.default;
|
|
19
20
|
return makeStorybookWebpackConfig(config, {
|
|
20
21
|
// storybook dev -> configType === 'DEVELOPMENT'
|
|
21
22
|
// storybook build -> configType === 'PRODUCTION'
|
|
@@ -24,7 +25,7 @@ const webpackFinal = async (config, { configType }) => {
|
|
|
24
25
|
};
|
|
25
26
|
/** @type {NonNullable<StorybookConfig['babel']>} */
|
|
26
27
|
const babel = async () => {
|
|
27
|
-
const createBabelConfig = (await import('../babel
|
|
28
|
+
const createBabelConfig = (await import('../babel.js')).default;
|
|
28
29
|
return createBabelConfig({
|
|
29
30
|
target: 'browser',
|
|
30
31
|
lang: 'ts',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { packageManagerOption } from '../../options/packageManager/packageManager.option.js';
|
|
3
|
-
import { setPackageManager } from '../../../services/packageManager/context
|
|
3
|
+
import { setPackageManager } from '../../../services/packageManager/context.js';
|
|
4
4
|
export const initCommand = new Command('init')
|
|
5
5
|
.description('Initialize a new sku project')
|
|
6
6
|
.argument('[projectName]', 'Project name')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveConfig } from '@vocab/core';
|
|
2
|
-
import { getVocabConfig } from '../../../../services/vocab/config/vocab.js';
|
|
3
2
|
import { execSync } from 'node:child_process';
|
|
3
|
+
import { getVocabConfig } from '../../../../services/vocab/config.js';
|
|
4
4
|
export const ensureBranch = async () => {
|
|
5
5
|
const branch = getGitBranch();
|
|
6
6
|
if (!branch) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
2
|
import { includeIgnoreFile } from '@eslint/compat';
|
|
3
|
-
import { createEslintIgnoresConfig } from './config/ignores.js';
|
|
4
3
|
import { getPathFromCwd } from '../../utils/cwd.js';
|
|
5
4
|
import exists from '../../utils/exists.js';
|
|
6
5
|
import { SkuConfigUpdater } from '../../utils/SkuConfigUpdater.js';
|
|
6
|
+
import { createEslintIgnoresConfig } from '../../config/eslint/ignores.js';
|
|
7
7
|
const oldEslintConfigPath = getPathFromCwd('.eslintrc');
|
|
8
8
|
const eslintIgnorePath = getPathFromCwd('.eslintignore');
|
|
9
9
|
export const shouldMigrateOldEslintConfig = async () => {
|
|
@@ -2,7 +2,7 @@ import { findUpSync } from 'find-up';
|
|
|
2
2
|
import { dirname } from 'node:path';
|
|
3
3
|
import { resolveCommand } from 'package-manager-detector/commands';
|
|
4
4
|
import { INSTALL_PAGE } from 'package-manager-detector/constants';
|
|
5
|
-
import { getPackageManager } from './context
|
|
5
|
+
import { getPackageManager } from './context.js';
|
|
6
6
|
import semver from 'semver';
|
|
7
7
|
const supportedPackageManagers = ['yarn', 'pnpm', 'npm'];
|
|
8
8
|
const validatePackageManager = (packageManager) => {
|
|
@@ -2,11 +2,12 @@ import banner from '../../utils/banners/banner.js';
|
|
|
2
2
|
import exists from '../../utils/exists.js';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import isCI from '../../utils/isCI.js';
|
|
5
6
|
const accent = chalk.blue.bold;
|
|
6
7
|
const info = chalk.bold;
|
|
7
8
|
export const validatePnpmConfig = async ({ rootDir, hasRecommendedPnpmVersionInstalled, pnpmPluginSkuInstalled, }) => {
|
|
8
9
|
const npmrcExists = await exists(path.join(rootDir, '.npmrc'));
|
|
9
|
-
if (npmrcExists) {
|
|
10
|
+
if (!isCI && npmrcExists) {
|
|
10
11
|
banner('warning', 'Detected .npmrc file', [
|
|
11
12
|
`Please migrate all ${accent('.npmrc')} configuration to ${accent('pnpm-workspace.yaml')} and add ${accent('.npmrc')} to your ${accent('.gitignore')}. See ${info('https://pnpm.io/settings')} for more information.`,
|
|
12
13
|
]);
|
|
@@ -7,7 +7,7 @@ import { suggestScript } from '../../utils/suggestScript.js';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
const prettierIgnorePath = getPathFromCwd('.prettierignore');
|
|
10
|
-
const prettierConfigPath = path.join(__dirname, '
|
|
10
|
+
const prettierConfigPath = path.join(__dirname, '../../config/prettier.js');
|
|
11
11
|
const runPrettier = async ({ write, listDifferent, paths, }) => {
|
|
12
12
|
console.log(chalk.cyan(`${write ? 'Formatting' : 'Checking'} code with Prettier`));
|
|
13
13
|
const prettierArgs = ['--config', prettierConfigPath, '--cache'];
|
|
@@ -8,7 +8,7 @@ import { preloadPlugin } from '../../plugins/preloadPlugin/preloadPlugin.js';
|
|
|
8
8
|
import { fixViteVanillaExtractDepScanPlugin } from '../../plugins/esbuild/fixViteVanillaExtractDepScanPlugin.js';
|
|
9
9
|
import { createVocabChunks } from '@vocab/vite/chunks';
|
|
10
10
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
11
|
-
import { getVocabConfig } from '../../../vocab/config
|
|
11
|
+
import { getVocabConfig } from '../../../vocab/config.js';
|
|
12
12
|
import vocabPluginVite from '@vocab/vite';
|
|
13
13
|
import { dangerouslySetViteConfig } from '../../plugins/dangerouslySetViteConfig.js';
|
|
14
14
|
import { setSsrNoExternal } from '../../plugins/setSsrNoExternal.js';
|
|
@@ -18,6 +18,8 @@ const getBaseConfig = (skuContext) => {
|
|
|
18
18
|
const vocabConfig = getVocabConfig(skuContext);
|
|
19
19
|
const isProductionBuild = process.env.NODE_ENV === 'production';
|
|
20
20
|
const prodBabelPlugins = [
|
|
21
|
+
require.resolve('babel-plugin-transform-react-remove-prop-types'),
|
|
22
|
+
require.resolve('@babel/plugin-transform-react-constant-elements'),
|
|
21
23
|
[
|
|
22
24
|
require.resolve('babel-plugin-unassert'),
|
|
23
25
|
{
|
|
@@ -53,9 +55,7 @@ const getBaseConfig = (skuContext) => {
|
|
|
53
55
|
],
|
|
54
56
|
},
|
|
55
57
|
}),
|
|
56
|
-
vanillaExtractPlugin(
|
|
57
|
-
unstable_mode: 'inlineCssInDev',
|
|
58
|
-
}),
|
|
58
|
+
vanillaExtractPlugin(),
|
|
59
59
|
preloadPlugin({
|
|
60
60
|
convertFromWebpack: skuContext.convertLoadable, // Convert loadable import from webpack to vite. Can be put behind a flag.
|
|
61
61
|
}),
|
|
@@ -8,6 +8,7 @@ import { httpsDevServerPlugin } from '../../plugins/httpsDevServerPlugin.js';
|
|
|
8
8
|
import { getAppHosts } from '../../../../utils/contextUtils/hosts.js';
|
|
9
9
|
import isCI from '../../../../utils/isCI.js';
|
|
10
10
|
import { bundleAnalyzerPlugin } from '../../plugins/bundleAnalyzer.js';
|
|
11
|
+
import { vitePluginSsrCss } from '../../plugins/ssrCss/plugin.js';
|
|
11
12
|
const require = createRequire(import.meta.url);
|
|
12
13
|
const clientEntry = require.resolve('../../entries/vite-client.js');
|
|
13
14
|
const shouldOpenTab = process.env.OPEN_TAB !== 'false' && !isCI;
|
|
@@ -50,6 +51,9 @@ export const createStartConfig = (skuContext) => {
|
|
|
50
51
|
return createSkuViteConfig({
|
|
51
52
|
base: '/',
|
|
52
53
|
plugins: [
|
|
54
|
+
vitePluginSsrCss({
|
|
55
|
+
entries: [skuContext.paths.renderEntry],
|
|
56
|
+
}),
|
|
53
57
|
middlewarePlugin(skuContext),
|
|
54
58
|
startTelemetryPlugin({
|
|
55
59
|
target: 'node',
|
|
@@ -2,13 +2,15 @@ import assert from 'node:assert';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs/promises';
|
|
4
4
|
import resolveSync from 'resolve-from';
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
const log = debug('sku:dependency-graph');
|
|
5
7
|
export const resolveFrom = async (fromDirectory, moduleId) => resolveSync(fromDirectory, moduleId);
|
|
6
8
|
const ROOT = 'ROOT';
|
|
7
9
|
const promiseMap = async (items, fn) => Promise.all(items.map(fn));
|
|
8
10
|
const loadPackage = async (packageJsonPath) => fs
|
|
9
11
|
.readFile(packageJsonPath, 'utf-8')
|
|
10
12
|
.then(JSON.parse);
|
|
11
|
-
const
|
|
13
|
+
const analyseDependency = async (dependent, dep, rootDir, depGraph) => {
|
|
12
14
|
const packageJsonPath = await resolveFrom(rootDir, `${dep}/package.json`);
|
|
13
15
|
const packageJson = await loadPackage(packageJsonPath);
|
|
14
16
|
const dependencies = Object.keys(packageJson.dependencies ?? {});
|
|
@@ -30,10 +32,18 @@ const anaylyseDependency = async (dependent, dep, rootDir, depGraph) => {
|
|
|
30
32
|
dependencies,
|
|
31
33
|
peerDependencies,
|
|
32
34
|
});
|
|
33
|
-
await promiseMap([...dependencies, ...peerDependencies], (childDep) =>
|
|
35
|
+
await promiseMap([...dependencies, ...peerDependencies], async (childDep) => {
|
|
36
|
+
try {
|
|
37
|
+
await analyseDependency(dep, childDep, path.dirname(packageJsonPath), depGraph);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
log(`Error analysing dependency ${childDep} for ${dep}.`, e);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
34
43
|
}
|
|
35
44
|
};
|
|
36
45
|
export const extractDependencyGraph = async (rootDir) => {
|
|
46
|
+
log('starting to extract dependency graph...');
|
|
37
47
|
const depGraph = new Map();
|
|
38
48
|
const packageJson = await loadPackage(`${rootDir}/package.json`);
|
|
39
49
|
const deps = Object.keys(packageJson.dependencies ?? {});
|
|
@@ -46,12 +56,13 @@ export const extractDependencyGraph = async (rootDir) => {
|
|
|
46
56
|
depGraph.set(ROOT, dependency);
|
|
47
57
|
await promiseMap(deps, async (childDep) => {
|
|
48
58
|
try {
|
|
49
|
-
await
|
|
59
|
+
await analyseDependency(ROOT, childDep, rootDir, depGraph);
|
|
50
60
|
}
|
|
51
|
-
catch {
|
|
52
|
-
|
|
61
|
+
catch (e) {
|
|
62
|
+
log(`Error analysing dependency ${childDep} for ${ROOT}.`, e);
|
|
53
63
|
}
|
|
54
64
|
});
|
|
65
|
+
log('finished extracting dependency graph');
|
|
55
66
|
return depGraph;
|
|
56
67
|
};
|
|
57
68
|
export const getSsrExternalsForCompiledDependency = (depName, depGraph) => {
|
|
@@ -70,7 +81,9 @@ export const getSsrExternalsForCompiledDependency = (depName, depGraph) => {
|
|
|
70
81
|
dependent.dependents.forEach((dep) => dependents.add(dep));
|
|
71
82
|
}
|
|
72
83
|
noExternals.delete(ROOT);
|
|
84
|
+
const noExternal = Array.from(noExternals);
|
|
85
|
+
log(`Found dependencies to prevent externalising for ${depName}:`, noExternal);
|
|
73
86
|
return {
|
|
74
|
-
noExternal
|
|
87
|
+
noExternal,
|
|
75
88
|
};
|
|
76
89
|
};
|
|
@@ -21,7 +21,7 @@ export const middlewarePlugin = (skuContext) => ({
|
|
|
21
21
|
log('Using dev server middleware at %s', skuContext.paths.devServerMiddleware);
|
|
22
22
|
const devServerMiddleware = (await import(skuContext.paths.devServerMiddleware)).default;
|
|
23
23
|
if (devServerMiddleware && typeof devServerMiddleware === 'function') {
|
|
24
|
-
devServerMiddleware(server);
|
|
24
|
+
devServerMiddleware(server.middlewares);
|
|
25
25
|
log('Dev server middleware loaded');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { mergeConfig } from 'vite';
|
|
2
1
|
import { extractDependencyGraph, getSsrExternalsForCompiledDependency, } from '../helpers/config/dependencyGraph.js';
|
|
3
2
|
export function setSsrNoExternal(skuContext) {
|
|
4
3
|
return {
|
|
5
4
|
name: 'vite-plugin-set-ssr-no-external',
|
|
6
|
-
|
|
5
|
+
async config() {
|
|
7
6
|
const depGraph = await extractDependencyGraph(process.cwd());
|
|
8
7
|
const ssrExternals = getSsrExternalsForCompiledDependency('@vanilla-extract/css', depGraph);
|
|
9
|
-
|
|
8
|
+
return {
|
|
10
9
|
ssr: {
|
|
11
10
|
noExternal: [
|
|
12
11
|
...skuContext.skuConfig.compilePackages,
|
|
13
12
|
...ssrExternals.noExternal,
|
|
14
13
|
],
|
|
15
14
|
},
|
|
16
|
-
}
|
|
17
|
-
return mergedConfig;
|
|
15
|
+
};
|
|
18
16
|
},
|
|
19
17
|
};
|
|
20
18
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// style collection
|
|
2
|
+
// https://github.com/remix-run/remix/blob/1a8a5216106bd8c3073cc3e5e5399a32c981db74/packages/remix-dev/vite/styles.ts
|
|
3
|
+
// https://github.com/vikejs/vike/blob/f9a91f3c47cab9c2871526ef714cc0f87a41fda0/vike/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.ts
|
|
4
|
+
// https://github.com/sveltejs/kit/blob/998edb26d431e4ee4d3b4dc792a86960a85a5b45/packages/kit/src/exports/vite/dev/index.js#L186-L219
|
|
5
|
+
// https://github.com/withastro/astro/blob/6aaeec5034cabf6a83e1949ec1ca8f50e7978cc1/packages/astro/src/vite-plugin-astro-server/css.ts
|
|
6
|
+
export async function collectStyle(server, entries) {
|
|
7
|
+
const urls = await collectStyleUrls(server, entries);
|
|
8
|
+
const codes = await Promise.all(urls.map(async (url) => {
|
|
9
|
+
const res = url.includes('\0')
|
|
10
|
+
? await server.ssrLoadModule(url).then((m) => m.default)
|
|
11
|
+
: await server
|
|
12
|
+
.transformRequest(`${url}?direct`)
|
|
13
|
+
.then((result) => result?.code);
|
|
14
|
+
return [`/* [collectStyle] ${url} */`, res];
|
|
15
|
+
}));
|
|
16
|
+
return codes.flat().filter(Boolean).join('\n\n');
|
|
17
|
+
}
|
|
18
|
+
async function collectStyleUrls(server, entries) {
|
|
19
|
+
const visited = new Set();
|
|
20
|
+
async function traverse(url) {
|
|
21
|
+
const [, id] = await server.moduleGraph.resolveUrl(url);
|
|
22
|
+
if (visited.has(id)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
visited.add(id);
|
|
26
|
+
const mod = server.moduleGraph.getModuleById(id);
|
|
27
|
+
if (!mod) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Sequential traversal for depth-first behavior
|
|
31
|
+
for (const childMod of mod.importedModules) {
|
|
32
|
+
await traverse(childMod.url);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// ensure vite's import analysis is ready _only_ for top entries to not go too aggresive
|
|
36
|
+
await Promise.all(entries.map((e) => server.transformRequest(e)));
|
|
37
|
+
// traverse sequentially for depth-first
|
|
38
|
+
for (const url of entries) {
|
|
39
|
+
await traverse(url);
|
|
40
|
+
}
|
|
41
|
+
// filter
|
|
42
|
+
return [...visited].filter((url) => url.match(CSS_LANGS_RE));
|
|
43
|
+
}
|
|
44
|
+
// cf. https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/constants.ts#L49C23-L50
|
|
45
|
+
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { vitePluginSsrCss } from './plugin.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { vitePluginSsrCss } from './plugin.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin provides virtual:ssr-css.css to collect styles reachable from entries.
|
|
4
|
+
* When using ViteDevServer.transformIndexHtml, it will inject <link rel="stylesheet" href="/@id/__x00__virtual:ssr-css.css" /> to <head>.
|
|
5
|
+
*
|
|
6
|
+
* This plugin has been forked from `hi-ogawa/vite-plugins`, with some adjustments to make it work with Sku + Braid.
|
|
7
|
+
* @see https://github.com/hi-ogawa/vite-plugins/blob/main/packages/ssr-css/README.md
|
|
8
|
+
*/
|
|
9
|
+
export declare function vitePluginSsrCss(pluginOpts: {
|
|
10
|
+
entries: string[];
|
|
11
|
+
}): Plugin;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { collectStyle } from './collect.js';
|
|
2
|
+
const PLUGIN_NAME = 'vite-plugin-ssr-css';
|
|
3
|
+
const VIRTUAL_ENTRY = 'virtual:ssr-css.css';
|
|
4
|
+
/**
|
|
5
|
+
* This plugin provides virtual:ssr-css.css to collect styles reachable from entries.
|
|
6
|
+
* When using ViteDevServer.transformIndexHtml, it will inject <link rel="stylesheet" href="/@id/__x00__virtual:ssr-css.css" /> to <head>.
|
|
7
|
+
*
|
|
8
|
+
* This plugin has been forked from `hi-ogawa/vite-plugins`, with some adjustments to make it work with Sku + Braid.
|
|
9
|
+
* @see https://github.com/hi-ogawa/vite-plugins/blob/main/packages/ssr-css/README.md
|
|
10
|
+
*/
|
|
11
|
+
export function vitePluginSsrCss(pluginOpts) {
|
|
12
|
+
let server;
|
|
13
|
+
const virtualHref = `/@id/__x00__${VIRTUAL_ENTRY}`;
|
|
14
|
+
return {
|
|
15
|
+
name: PLUGIN_NAME,
|
|
16
|
+
apply: 'serve',
|
|
17
|
+
configureServer(server_) {
|
|
18
|
+
server = server_;
|
|
19
|
+
// invalidate virtual modules for each direct request
|
|
20
|
+
server.middlewares.use((req, _res, next) => {
|
|
21
|
+
if (req.url === virtualHref) {
|
|
22
|
+
invalidateModule(server, `\0${VIRTUAL_ENTRY}?direct`);
|
|
23
|
+
}
|
|
24
|
+
next();
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
// virtual module
|
|
28
|
+
// (use `startsWith` since Vite adds `?direct` for raw css request)
|
|
29
|
+
resolveId(source, _importer, _options) {
|
|
30
|
+
return source.startsWith(VIRTUAL_ENTRY) ? `\0${source}` : undefined;
|
|
31
|
+
},
|
|
32
|
+
async load(id, _options) {
|
|
33
|
+
if (id.startsWith(`\0${VIRTUAL_ENTRY}`)) {
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(id.slice(1), 'https://test.local');
|
|
36
|
+
let code = await collectStyle(server, pluginOpts.entries);
|
|
37
|
+
if (!url.searchParams.has('direct')) {
|
|
38
|
+
code = `export default ${JSON.stringify(code)}`;
|
|
39
|
+
}
|
|
40
|
+
return code;
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
console.error(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
},
|
|
48
|
+
// also expose via transformIndexHtml
|
|
49
|
+
transformIndexHtml: {
|
|
50
|
+
handler: async () => [
|
|
51
|
+
{
|
|
52
|
+
tag: 'link',
|
|
53
|
+
injectTo: 'head',
|
|
54
|
+
attrs: {
|
|
55
|
+
rel: 'stylesheet',
|
|
56
|
+
href: virtualHref,
|
|
57
|
+
'data-ssr-css': true,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
tag: 'script',
|
|
62
|
+
injectTo: 'head',
|
|
63
|
+
attrs: { type: 'module' },
|
|
64
|
+
children: /* js */ `
|
|
65
|
+
import { createHotContext } from "/@vite/client";
|
|
66
|
+
const hot = createHotContext("/__clear_ssr_css");
|
|
67
|
+
hot.on("vite:afterUpdate", () => {
|
|
68
|
+
document
|
|
69
|
+
.querySelectorAll("[data-ssr-css]")
|
|
70
|
+
.forEach(node => node.remove());
|
|
71
|
+
});
|
|
72
|
+
`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function invalidateModule(server, id) {
|
|
79
|
+
const mod = server.moduleGraph.getModuleById(id);
|
|
80
|
+
if (mod) {
|
|
81
|
+
server.moduleGraph.invalidateModule(mod);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -9,7 +9,7 @@ type BabelConfigOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
export declare const makeJsLoaders: (options: BabelConfigOptions) => {
|
|
11
11
|
loader: string;
|
|
12
|
-
options: import("../../../../config/babel
|
|
12
|
+
options: import("../../../../config/babel.js").SkuBabelConfig;
|
|
13
13
|
}[];
|
|
14
14
|
type MakeExternalCssLoadersOptions = {
|
|
15
15
|
target: 'node' | 'browser';
|
|
@@ -13,7 +13,7 @@ import MetricsPlugin from './plugins/metrics-plugin/index.js';
|
|
|
13
13
|
import { VocabWebpackPlugin } from '@vocab/webpack';
|
|
14
14
|
import { JAVASCRIPT, resolvePackage } from './utils/index.js';
|
|
15
15
|
import { cwd } from '../../../utils/cwd.js';
|
|
16
|
-
import { getVocabConfig } from '../../vocab/config
|
|
16
|
+
import { getVocabConfig } from '../../vocab/config.js';
|
|
17
17
|
import getStatsConfig from './statsConfig.js';
|
|
18
18
|
import getSourceMapSetting from './sourceMaps.js';
|
|
19
19
|
import getCacheSettings from './cache.js';
|
|
@@ -14,7 +14,7 @@ import { VocabWebpackPlugin } from '@vocab/webpack';
|
|
|
14
14
|
import { bundleAnalyzerPlugin } from './plugins/bundleAnalyzer.js';
|
|
15
15
|
import { JAVASCRIPT, resolvePackage } from './utils/index.js';
|
|
16
16
|
import { requireFromCwd } from '../../../utils/cwd.js';
|
|
17
|
-
import { getVocabConfig } from '../../vocab/config
|
|
17
|
+
import { getVocabConfig } from '../../vocab/config.js';
|
|
18
18
|
import getStatsConfig from './statsConfig.js';
|
|
19
19
|
import getSourceMapSetting from './sourceMaps.js';
|
|
20
20
|
import getCacheSettings from './cache.js';
|
|
@@ -204,6 +204,7 @@ const makeWebpackConfig = ({ clientPort, serverPort, isDevServer = false, hot =
|
|
|
204
204
|
path: paths.target,
|
|
205
205
|
publicPath,
|
|
206
206
|
filename: `server.${type === 'module' ? 'c' : ''}js`,
|
|
207
|
+
hotUpdateChunkFilename: `[id].[fullhash].hot-update.${type === 'module' ? 'c' : ''}js`,
|
|
207
208
|
library: { name: 'server', type: 'var' },
|
|
208
209
|
},
|
|
209
210
|
cache: getCacheSettings({ isDevServer, paths }),
|
|
@@ -5,7 +5,7 @@ import { parseModule, builders, generateCode, } from 'magicast';
|
|
|
5
5
|
import { getConfigFromVariableDeclaration } from 'magicast/helpers';
|
|
6
6
|
import debug from 'debug';
|
|
7
7
|
import prettier from 'prettier';
|
|
8
|
-
import prettierConfig from '../
|
|
8
|
+
import prettierConfig from '../config/prettier.js';
|
|
9
9
|
const log = debug('sku:update-sku-config');
|
|
10
10
|
export class SkuConfigUpdater {
|
|
11
11
|
/** The AST or AST proxy of the sku config */
|
|
@@ -3,8 +3,8 @@ import path from 'node:path';
|
|
|
3
3
|
import dedent from 'dedent';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import ensureGitignore from 'ensure-gitignore';
|
|
6
|
-
import prettierConfig from '../
|
|
7
|
-
import createTSConfig from '../services/typescript/
|
|
6
|
+
import prettierConfig from '../config/prettier.js';
|
|
7
|
+
import createTSConfig from '../services/typescript/tsconfig.js';
|
|
8
8
|
import { bundleReportFolder } from '../services/webpack/config/plugins/bundleAnalyzer.js';
|
|
9
9
|
import { shouldMigrateOldEslintConfig, migrateEslintignore, cleanUpOldEslintFiles, addEslintIgnoreToSkuConfig, } from '../services/eslint/eslintMigration.js';
|
|
10
10
|
import getCertificate from './certificate.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sku",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.10.0",
|
|
4
4
|
"description": "Front-end development toolkit, powered by Webpack, Babel, Vanilla Extract and Jest",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"bin": {
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"require": "./dist/index.d.cts"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"./jest-preset": "./dist/config/jest/
|
|
16
|
+
"./jest-preset": "./dist/config/jest/preset.js",
|
|
17
17
|
"./config/eslint": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"default": "./dist/
|
|
18
|
+
"types": "./dist/config/eslint/config.d.ts",
|
|
19
|
+
"default": "./dist/config/eslint/config.js"
|
|
20
20
|
},
|
|
21
21
|
"./config/storybook": {
|
|
22
|
-
"types": "./dist/config/storybook/
|
|
23
|
-
"default": "./dist/config/storybook/
|
|
22
|
+
"types": "./dist/config/storybook/config.d.ts",
|
|
23
|
+
"default": "./dist/config/storybook/config.cjs"
|
|
24
24
|
},
|
|
25
25
|
"./vite/loadable": {
|
|
26
26
|
"types": "./dist/services/vite/loadable/index.d.ts",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|