Skip to content

Commit

Permalink
update: AIK 0.8 (#59)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Lefebvre <[email protected]>
  • Loading branch information
Fryuni and florian-lefebvre authored Mar 25, 2024
1 parent 146c276 commit a81f657
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 63 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-snails-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inox-tools/sitemap-ext": patch
---

Update to AIK 0.8
6 changes: 6 additions & 0 deletions .changeset/violet-flies-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@inox-tools/aik-route-config": minor
"@inox-tools/aik-mod": minor
---

Update to AIK 0.8
2 changes: 1 addition & 1 deletion examples/inline-mod-aik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@inox-tools/aik-mod": "workspace:^",
"astro-integration-kit": "^0.7.1"
"astro-integration-kit": "^0.8.0"
},
"overrides": {
"vite": "$vite"
Expand Down
3 changes: 1 addition & 2 deletions packages/aik-mod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@
"devDependencies": {
"@types/node": "^20.11.25",
"astro": "^4.4.15",
"astro-integration-kit": "^0.7.1",
"tsup": "^8.0.2",
"typescript": "^5.4.2",
"vite": "^5.1.5"
},
"peerDependencies": {
"astro": "^4.3.5",
"astro-integration-kit": "~0.7"
"astro-integration-kit": "~0.8"
}
}
2 changes: 1 addition & 1 deletion packages/aik-route-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
},
"peerDependencies": {
"astro": "^4.3.5",
"astro-integration-kit": "~0.7"
"astro-integration-kit": "~0.8"
}
}
41 changes: 18 additions & 23 deletions packages/aik-route-config/src/contextResolution.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { HookParameters, RouteData } from 'astro';
import * as path from 'node:path';
import { addIntegration } from 'astro-integration-kit/utilities';
import { Once } from './once.js';
import { defineIntegration } from 'astro-integration-kit';
import { addVitePluginPlugin } from 'astro-integration-kit/plugins';
import { defineIntegration, addIntegration, addVitePlugin } from 'astro-integration-kit';
import { fileURLToPath } from 'node:url';
import { normalizePath } from 'vite';

Expand All @@ -27,30 +25,32 @@ const componentToContextMapping = new Map<string, ConfigContext>();

const integration = defineIntegration({
name: '@inox-tools/aik-route-config/context-resolution',
plugins: [addVitePluginPlugin],
setup: () => {
let root!: URL;

return {
'astro:config:setup': ({ addVitePlugin, config }) => {
'astro:config:setup': (params) => {
const { config } = params;
root = config.root;

addVitePlugin({
name: '@inox-tools/aik-route-config/context-resolution',
async writeBundle(outputOptions, bundle) {
const basePath = outputOptions.dir!;
addVitePlugin(params, {
plugin: {
name: '@inox-tools/aik-route-config/context-resolution',
async writeBundle(outputOptions, bundle) {
const basePath = outputOptions.dir!;

for (const chunk of Object.values(bundle)) {
if (chunk.type !== 'chunk') continue;
for (const chunk of Object.values(bundle)) {
if (chunk.type !== 'chunk') continue;

const fileName = path.join(basePath, chunk.fileName);
const fileName = path.join(basePath, chunk.fileName);

for (const id of chunk.moduleIds) {
if (id.endsWith('.astro')) {
componentToChunkMapping.set(id, fileName);
for (const id of chunk.moduleIds) {
if (id.endsWith('.astro')) {
componentToChunkMapping.set(id, fileName);
}
}
}
}
},
},
});
},
Expand Down Expand Up @@ -97,14 +97,9 @@ type IntegrateParams = HookParameters<'astro:config:setup'>;

export function integrate(params: IntegrateParams) {
integrateOnce.do(() => {
addIntegration({
config: params.config,
logger: params.logger,
updateConfig: params.updateConfig,
addIntegration(params, {
integration: integration(),
options: {
ensureUnique: true,
},
ensureUnique: true,
});
});
}
14 changes: 5 additions & 9 deletions packages/aik-route-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { definePlugin } from 'astro-integration-kit';
import { addVitePlugin } from 'astro-integration-kit/utilities';
import { definePlugin, addVitePlugin } from 'astro-integration-kit';
import { hoistGlobalPlugin } from './hoistGlobalPlugin.js';
import { integrate, convertContext } from './contextResolution.js';
import type { ConfigContext, InnerContext } from './contextResolution.js';
Expand All @@ -22,11 +21,11 @@ const globalHandlers: Map<string, InnerHandler<any>> = ((globalThis as any)[
export default definePlugin({
name: 'defineRouteConfig',
hook: 'astro:config:setup',
implementation: (astroConfig) => {
const { logger, updateConfig, config, command } = astroConfig;
implementation: (params) => {
const { logger, command } = params;

return <T = any>(options: PerRouteConfigOptions<T>): void => {
integrate(astroConfig);
integrate(params);

const innerHandler: InnerHandler<T> = async (context, value) => {
// Do nothing while running dev or preview server
Expand All @@ -44,15 +43,12 @@ export default definePlugin({

globalHandlers.set(options.importName, innerHandler);

addVitePlugin({
addVitePlugin(params, {
plugin: hoistGlobalPlugin({
configImport: options.importName,
logger,
}),
warnDuplicated: true,
updateConfig,
config,
logger,
});
};
},
Expand Down
28 changes: 13 additions & 15 deletions packages/sitemap-ext/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { defineIntegration } from 'astro-integration-kit';
import { defineIntegration, addIntegration, hasIntegration } from 'astro-integration-kit';
import routeConfigPlugin from '@inox-tools/aik-route-config';
import { AstroError } from 'astro/errors';
import { type RouteData } from 'astro';
import { EnumChangefreq } from 'sitemap';
import { z } from 'astro/zod';
import * as path from 'node:path';
import {
addVirtualImportsPlugin,
addIntegrationPlugin,
hasIntegrationPlugin,
} from 'astro-integration-kit/plugins';
import sitemap from '@astrojs/sitemap';
import './virtual.d.ts';

Expand All @@ -33,7 +28,7 @@ export default defineIntegration({
priority: z.number().optional(),
})
.default({}),
plugins: [addVirtualImportsPlugin, addIntegrationPlugin, hasIntegrationPlugin, routeConfigPlugin],
plugins: [routeConfigPlugin],
setup: ({ options: { includeByDefault, customPages: _externalPages, ...options } }) => {
type InclusionRule =
| { type: 'regex'; regex: RegExp; decision: boolean }
Expand Down Expand Up @@ -65,8 +60,10 @@ export default defineIntegration({
let baseUrl!: URL;

return {
'astro:config:setup': ({ defineRouteConfig, hasIntegration, addIntegration, config }) => {
if (hasIntegration('@astrojs/sitemap')) {
'astro:config:setup': (params) => {
const { defineRouteConfig, config } = params;

if (hasIntegration(params, { name: '@astrojs/sitemap' })) {
throw new AstroError(
'Cannot use both `@inox-tools/declarative-sitemap` and `@astrojs/sitemap` integrations at the same time.',
'Remove the `@astrojs/sitemap` integration from your project to use `@inox-tools/declarative-sitemap`.'
Expand Down Expand Up @@ -99,8 +96,8 @@ export default defineIntegration({
},
setSitemap(routeOptions) {
for (const route of context.routeData) {
for (const { sitemap: decision, params } of routeOptions) {
makeDecision(decision ?? includeByDefault, route, [params]);
for (const { sitemap: decision, params: routeParams } of routeOptions) {
makeDecision(decision ?? includeByDefault, route, [routeParams]);
}
}
},
Expand All @@ -119,8 +116,9 @@ export default defineIntegration({
});

// The sitemap integration will run _after_ the build is done, so after the build re-mapping done below.
addIntegration(
sitemap({
addIntegration(params, {
ensureUnique: true,
integration: sitemap({
...options,
// This relies on an internal detail of the sitemap integration that the reference
// to the array is passed around without being copied.
Expand All @@ -137,8 +135,8 @@ export default defineIntegration({

return ruling?.decision ?? includeByDefault;
},
})
);
}),
});
},
'astro:build:done': async ({ pages }) => {
const extraPagesSet = new Set<string>(
Expand Down
2 changes: 1 addition & 1 deletion packages/sitemap-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@astrojs/sitemap": "^3.1.1",
"@inox-tools/aik-route-config": "workspace:^",
"astro-integration-kit": "^0.7.1",
"astro-integration-kit": "^0.8.0",
"sitemap": "^7.1.1"
},
"devDependencies": {
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a81f657

Please sign in to comment.