Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V14 entry ts refactor #1141

Merged
merged 22 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eighty-masks-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'sku': minor
---
Add WebP and AVIF image format support to sku

Support for `webp` and `avif` image formats has been added. Note that browser support for these formats may vary. To ensure compatibility across browsers, consumers are advised to use the `<picture>` element with fallback formats.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ jobs:
run: sudo chmod +x /home/runner/work/sku/sku/packages/sku/dist/bin/sku.js

- name: Test
run: pnpm run test && pnpm run test:sku-init
run: aa-exec --profile=chrome pnpm run test && aa-exec --profile=chrome pnpm run test:sku-init
12 changes: 11 additions & 1 deletion docs/docs/extra-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
## Images

The following images types are supported in sku:
`bmp`, `gif`, `jpeg`, `png` and `svg`.
`bmp`, `gif`, `jpeg`, `png`, `svg`, `webp` and `avif`.

?> Browser support for `webp` and `avif` varies. To ensure compatability across browsers, consider providing fallback image formats using the [`picture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture) element.

```html
<picture>
<source srcset="image.avif" type="image/avif" />
<source srcset="image.webp" type="image/webp" />
<img src="image.png" />
</picture>
```

If you want to use a currently unsupported format feel free to submit a PR or contact #sku-support.

Expand Down
2 changes: 0 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module.exports = [
'!test/test-cases/*/*.test.js',
'fixtures/*/*',
'**/@loadable/**/*',
'**/*.test.js',
'**/*.test.ts',
],
},
...seek,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/translations/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.eslintcache
.prettierrc
coverage/
dist/
dist-ssr/
DanDroryAu marked this conversation as resolved.
Show resolved Hide resolved
eslint.config.mjs
report/
tsconfig.json
Expand Down
2 changes: 1 addition & 1 deletion fixtures/translations/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ translations.ts
.eslintcache
.prettierrc
coverage/
dist/
dist-ssr/
eslint.config.mjs
pnpm-lock.yaml
report/
Expand Down
4 changes: 2 additions & 2 deletions fixtures/translations/src/server.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { renderToString } from 'react-dom/server';
import { VocabProvider } from '@vocab/react';
import { renderToString } from 'react-dom/server';
import type { Server } from 'sku';

import App from './App';
import type { Server } from 'sku';

const initialResponseTemplate = ({ headTags }: any) => /* html */ `
<!DOCTYPE html>
Expand Down
1 change: 1 addition & 0 deletions packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"@types/react": "^18.2.3",
"@types/react-dom": "^18.2.3",
"@types/semver": "^7.5.8",
"@types/serialize-javascript": "^5.0.4",
"@types/serve-handler": "^6.1.4",
"@types/webpack-bundle-analyzer": "^4.7.0",
"@types/webpack-node-externals": "^3.0.4",
Expand Down
15 changes: 8 additions & 7 deletions packages/sku/sku-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ interface SkuSiteObject {

type SkuSite = string | SkuSiteObject;

interface TranformOutputPathFunctionParams {
environment: string;
site: string;
path: string;
interface TransformOutputPathFunctionParams {
environment: string | undefined;
site: string | undefined;
route: string;
}
type TranformOutputPathFunction = (
input: TranformOutputPathFunctionParams,

type TransformOutputPathFunction = (
input: TransformOutputPathFunctionParams,
) => string;

type SkuLanguage = string | { name: string; extends?: string };
Expand Down Expand Up @@ -467,5 +468,5 @@ export interface SkuConfig {
*
* @link https://seek-oss.github.io/sku/#/./docs/configuration?id=transformoutputpath
*/
transformOutputPath?: TranformOutputPathFunction;
transformOutputPath?: TransformOutputPathFunction;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const getStartRoutes = () => {
routeName: route.name,
route: getRouteWithLanguage(route.route, language),
language,
path: '',
}));
};

Expand Down Expand Up @@ -122,11 +123,6 @@ const createHtmlRenderPlugin = () => {
renderDirectory: paths.target,
routes: allRoutes,
skipAssets: isStartScript,
// Incompatible type here. In the SkuConfig type the `transformOutputPath` input is the following type:
// environment: string;
// site: string;
// path: string; Path does not exist in the transformFilePath type that the HTMLRenderPLugin accepts.
// @ts-expect-error
transformFilePath: transformOutputPath,
mapStatsToParams,
extraGlobals: {
Expand Down
14 changes: 0 additions & 14 deletions packages/sku/src/context/configPath.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/sku/src/context/configPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let configPath: string | undefined;

export const getConfigPath = () => configPath;

export const setConfigPath = (path: string | undefined) => {
configPath = path;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Validator from 'fastest-validator';

const validator = new Validator();
const validator = new (Validator as unknown as typeof Validator.default)();

const languagesToCompile = {
optional: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { posix as path } from 'node:path';
import chalk from 'chalk';
import { fdir as Fdir } from 'fdir';
import _debug from 'debug';
import { createRequire } from 'node:module';

import toPosixPath from '../lib/toPosixPath.js';

import { rootDir, isPnpm } from '../lib/packageManager.js';
import _debug from 'debug';

const debug = _debug('sku:compilePackages');

/** @type {string[]} */
let detectedCompilePackages = [];
const require = createRequire(import.meta.url);

let detectedCompilePackages: string[] = [];

// If there's no rootDir, we're either inside `sku init`, or we can't determine the user's
// package manager. In either case, we can't correctly detect compile packages.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import browserslistConfigSeek from 'browserslist-config-seek';
import { join } from 'node:path';
import isCompilePackage from '../lib/isCompilePackage.js';
import type { SkuConfig } from '../../sku-types.d.ts';

const defaultDecorator = (a) => a;
const defaultDecorator = <T>(a: T) => a;

/** @type {import("../../sku-types.d.ts").SkuConfig} */
export default {
clientEntry: 'src/client.js',
renderEntry: 'src/render.js',
serverEntry: 'src/server.js',
libraryEntry: null,
libraryEntry: undefined,
routes: [],
sites: [],
environments: [],
Expand All @@ -21,13 +21,13 @@ export default {
port: 8080,
serverPort: 8181,
target: 'dist',
setupTests: null,
initialPath: null,
setupTests: undefined,
initialPath: undefined,
public: 'public',
publicPath: '/',
polyfills: [],
libraryName: null,
libraryFile: null,
libraryName: undefined,
libraryFile: undefined,
sourceMapsProd: true,
displayNamesProd: false,
dangerouslySetWebpackConfig: defaultDecorator,
Expand All @@ -39,9 +39,9 @@ export default {
cspEnabled: false,
cspExtraScriptSrcHosts: [],
httpsDevServer: false,
devServerMiddleware: null,
devServerMiddleware: undefined,
rootResolution: !isCompilePackage,
languages: null,
languages: undefined,
skipPackageCompatibilityCompilation: [],
externalizeNodeModules: false,
};
} satisfies SkuConfig;
14 changes: 0 additions & 14 deletions packages/sku/src/context/packageManager.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/sku/src/context/packageManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let packageManager: string | undefined;

export const getPackageManager = () => packageManager;

export const setPackageManager = (pm: string | undefined) => {
packageManager = pm;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import didYouMean from 'didyoumean2';
import configSchema from './configSchema.js';
import defaultSkuConfig from './defaultSkuConfig.js';
import defaultClientEntry from './defaultClientEntry.js';
import type { SkuConfig } from '../../sku-types.d.ts';
import { hasErrorMessage } from '../lib/utils/error-guards.js';
import type { ValidationError } from 'fastest-validator';

const availableConfigKeys = Object.keys(defaultSkuConfig);

const exitWithErrors = async (errors) => {
const exitWithErrors = async (errors: string[]) => {
console.log(chalk.bold(chalk.underline(chalk.red('Errors in sku config:'))));
errors.forEach((error) => {
console.log(chalk.yellow(error));
});
process.exit(1);
};

export default (skuConfig) => {
export default (skuConfig: SkuConfig) => {
const errors = [];

// Validate extra keys
Expand All @@ -32,15 +35,17 @@ export default (skuConfig) => {
});

// Validate schema types
const schemaCheckResult = configSchema(skuConfig);
if (schemaCheckResult !== true) {
schemaCheckResult.forEach(({ message, field }) => {
const errorMessage = message
? `🚫 ${message.replace(field, `${chalk.bold(field)}`)}`
: `🚫 '${chalk.bold(field)}' is invalid`;
if (!configSchema.async) {
const schemaCheckResult = configSchema(skuConfig);
if (schemaCheckResult !== true) {
schemaCheckResult.forEach(({ message, field }: ValidationError) => {
const errorMessage = message
? `🚫 ${message.replace(field, `${chalk.bold(field)}`)}`
: `🚫 '${chalk.bold(field)}' is invalid`;

errors.push(errorMessage);
});
errors.push(errorMessage);
});
}
}

// Validate library entry has corresponding libraryName
Expand All @@ -55,25 +60,29 @@ export default (skuConfig) => {
}

// Ensure defaultClientEntry is not configured as a route name
skuConfig.routes.forEach(({ name }) => {
if (name === defaultClientEntry) {
errors.push(
`🚫 Invalid route name: '${chalk.bold(
defaultClientEntry,
)}', please use a different route name`,
);
skuConfig.routes?.forEach((skuRoute) => {
if (typeof skuRoute !== 'string') {
if (skuRoute.name === defaultClientEntry) {
errors.push(
`🚫 Invalid route name: '${chalk.bold(
defaultClientEntry,
)}', please use a different route name`,
);
}
}
});

// Ensure supportedBrowsers is valid browserslist query
try {
browserslist(skuConfig.supportedBrowsers);
} catch (e) {
errors.push(
`🚫 '${chalk.bold(
'supportedBrowsers',
)}' must be a valid browserslist query. ${chalk.white(e.message)}`,
);
if (hasErrorMessage(e)) {
errors.push(
`🚫 '${chalk.bold(
'supportedBrowsers',
)}' must be a valid browserslist query. ${chalk.white(e.message)}`,
);
}
}

if (errors.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// '__sku_alias__clientEntry' is a webpack alias
// pointing to the consuming apps client entry
import client from '__sku_alias__clientEntry';
import dedent from 'dedent';

import { loadableReady } from '@loadable/component';

import clientContextKey from '../clientContextKey.js';

if (process.env.NODE_ENV === 'development') {
if (typeof client !== 'function') {
throw new Error(require('dedent')`
throw new Error(dedent`
The sku client entry ('${__SKU_CLIENT_PATH__}') must export a function that calls hydrateRoot. e.g.

import { hydrateRoot } from 'react-dom/client';
Expand All @@ -31,7 +32,7 @@ loadableReady(() => {

const dataElement = document.getElementById(clientContextKey);
if (dataElement) {
clientContext = JSON.parse(dataElement.textContent);
clientContext = JSON.parse(dataElement.textContent || '{}');
}

client(clientContext);
Expand Down
File renamed without changes.
Loading
Loading