@wuchale/astro 0.3.0 → 0.3.2
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/dist/index.d.ts +2 -22
- package/dist/index.js +3 -23
- package/dist/runtime.d.ts +1 -1
- package/dist/transformer.d.ts +6 -6
- package/dist/transformer.js +6 -8
- package/package.json +5 -4
- package/src/loaders/astro.js +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
import type { Adapter, AdapterArgs, CreateHeuristicOpts, HeuristicFunc, LoaderChoice, RuntimeConf } from 'wuchale';
|
|
2
|
-
/**
|
|
3
|
-
* Create a heuristic function optimized for Astro files
|
|
4
|
-
* Uses the default heuristic which handles translatable vs non-translatable strings
|
|
5
|
-
*/
|
|
1
|
+
import type { Adapter, AdapterArgs, CreateHeuristicOpts, DeepPartial, HeuristicFunc, LoaderChoice, RuntimeConf } from 'wuchale';
|
|
6
2
|
export declare function createAstroHeuristic(opts: CreateHeuristicOpts): HeuristicFunc;
|
|
7
|
-
/** Default Svelte heuristic which extracts top level variable assignments as well, leading to `$derived` being auto added when needed */
|
|
8
3
|
export declare const astroDefaultHeuristic: HeuristicFunc;
|
|
9
4
|
type LoadersAvailable = 'default';
|
|
10
5
|
export type AstroArgs = Omit<AdapterArgs<LoadersAvailable>, 'bundleLoad' | 'granularLoad' | 'generateLoadID' | 'runtime'>;
|
|
11
6
|
export declare const defaultRuntime: RuntimeConf;
|
|
12
7
|
export declare const defaultArgs: AstroArgs;
|
|
13
8
|
export declare function getDefaultLoaderPath(loader: LoaderChoice<LoadersAvailable>): string | null;
|
|
14
|
-
|
|
15
|
-
* Create an Astro adapter for wuchale
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```js
|
|
19
|
-
* // wuchale.config.js
|
|
20
|
-
* import { adapter as astro } from '@wuchale/astro'
|
|
21
|
-
*
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* adapters: {
|
|
24
|
-
* astro: astro({ files: 'src/pages/**\/*.astro' })
|
|
25
|
-
* }
|
|
26
|
-
* })
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare const adapter: (args?: Partial<AstroArgs>) => Adapter;
|
|
9
|
+
export declare const adapter: (args?: DeepPartial<AstroArgs>) => Adapter;
|
|
30
10
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { createHeuristic,
|
|
1
|
+
import { createHeuristic, defaultGenerateLoadID, defaultHeuristicOpts, fillDefaults, pofile } from 'wuchale';
|
|
2
2
|
import { loaderPathResolver } from 'wuchale/adapter-utils';
|
|
3
3
|
import { pluralPattern } from 'wuchale/adapter-vanilla';
|
|
4
4
|
import { AstroTransformer } from './transformer.js';
|
|
5
|
-
/**
|
|
6
|
-
* Create a heuristic function optimized for Astro files
|
|
7
|
-
* Uses the default heuristic which handles translatable vs non-translatable strings
|
|
8
|
-
*/
|
|
9
5
|
export function createAstroHeuristic(opts) {
|
|
10
6
|
const defaultHeuristic = createHeuristic(opts);
|
|
11
7
|
return msg => {
|
|
@@ -22,7 +18,6 @@ export function createAstroHeuristic(opts) {
|
|
|
22
18
|
return defRes;
|
|
23
19
|
};
|
|
24
20
|
}
|
|
25
|
-
/** Default Svelte heuristic which extracts top level variable assignments as well, leading to `$derived` being auto added when needed */
|
|
26
21
|
export const astroDefaultHeuristic = createAstroHeuristic(defaultHeuristicOpts);
|
|
27
22
|
export const defaultRuntime = {
|
|
28
23
|
// Astro is SSR-only, so we use non-reactive runtime by default
|
|
@@ -53,23 +48,8 @@ export function getDefaultLoaderPath(loader) {
|
|
|
53
48
|
// just 'default', so
|
|
54
49
|
return resolveLoaderPath('astro');
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```js
|
|
61
|
-
* // wuchale.config.js
|
|
62
|
-
* import { adapter as astro } from '@wuchale/astro'
|
|
63
|
-
*
|
|
64
|
-
* export default defineConfig({
|
|
65
|
-
* adapters: {
|
|
66
|
-
* astro: astro({ files: 'src/pages/**\/*.astro' })
|
|
67
|
-
* }
|
|
68
|
-
* })
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export const adapter = (args = {}) => {
|
|
72
|
-
const { heuristic, patterns, loader, ...rest } = deepMergeObjects(args, defaultArgs);
|
|
51
|
+
export const adapter = (args = defaultArgs) => {
|
|
52
|
+
const { heuristic, patterns, loader, ...rest } = fillDefaults(args, defaultArgs);
|
|
73
53
|
return {
|
|
74
54
|
transform: async ({ content, filename, index, expr, matchUrl }) => {
|
|
75
55
|
return new AstroTransformer(content, filename, index, heuristic, patterns, expr, defaultRuntime, matchUrl).transformAs();
|
package/dist/runtime.d.ts
CHANGED
package/dist/transformer.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { AttributeNode, ComponentNode, CustomElementNode, ElementNode, ExpressionNode, FragmentNode, FrontmatterNode, Node, RootNode, TextNode } from '@astrojs/compiler/types';
|
|
1
|
+
import type { AttributeNode, CommentNode, ComponentNode, CustomElementNode, ElementNode, ExpressionNode, FragmentNode, FrontmatterNode, Node, RootNode, TextNode } from '@astrojs/compiler/types';
|
|
2
2
|
import type * as Estree from 'acorn';
|
|
3
3
|
import type { CatalogExpr, CodePattern, HeuristicFunc, IndexTracker, Message, RuntimeConf, TransformOutput, UrlMatcher } from 'wuchale';
|
|
4
4
|
import { MixedVisitor } from 'wuchale/adapter-utils';
|
|
5
5
|
import { Transformer } from 'wuchale/adapter-vanilla';
|
|
6
6
|
export declare function parseExpr(content: string): [Estree.Expression, Estree.Comment[][]];
|
|
7
|
-
type
|
|
7
|
+
type MixedVisitorAstro = MixedVisitor<Node, TextNode, CommentNode, ExpressionNode>;
|
|
8
8
|
export declare class AstroTransformer extends Transformer {
|
|
9
9
|
byteArray: Uint8Array;
|
|
10
|
-
currentElement?: string;
|
|
10
|
+
currentElement?: string | undefined;
|
|
11
11
|
inCompoundText: boolean;
|
|
12
12
|
frontMatterStart?: number;
|
|
13
|
-
mixedVisitor:
|
|
13
|
+
mixedVisitor: MixedVisitorAstro;
|
|
14
14
|
correctedExprRanges: WeakMap<Node | AttributeNode, {
|
|
15
15
|
start: number;
|
|
16
16
|
end: number;
|
|
@@ -22,14 +22,14 @@ export declare class AstroTransformer extends Transformer {
|
|
|
22
22
|
start: number;
|
|
23
23
|
end: number;
|
|
24
24
|
};
|
|
25
|
-
initMixedVisitor: () =>
|
|
25
|
+
initMixedVisitor: () => MixedVisitorAstro;
|
|
26
26
|
_parseAndVisitExpr: (expr: string, startOffset: number, asScript?: boolean) => Message[];
|
|
27
27
|
visitexpression: (node: ExpressionNode) => Message[];
|
|
28
28
|
_visitChildren: (nodes: Node[]) => Message[];
|
|
29
29
|
visitFragmentNode: (node: FragmentNode) => Message[];
|
|
30
30
|
visitelement: (node: ElementNode) => Message[];
|
|
31
31
|
visitcomponent: (node: ComponentNode) => Message[];
|
|
32
|
-
|
|
32
|
+
'visitcustom-element': (node: CustomElementNode) => Message[];
|
|
33
33
|
visitattribute: (node: AttributeNode) => Message[];
|
|
34
34
|
visittext: (node: TextNode) => Message[];
|
|
35
35
|
visitfrontmatter: (node: FrontmatterNode) => Message[];
|
package/dist/transformer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parse } from '@astrojs/compiler';
|
|
2
2
|
import { tsPlugin } from '@sveltejs/acorn-typescript';
|
|
3
3
|
import { Parser } from 'acorn';
|
|
4
|
-
import MagicString from 'magic-string';
|
|
5
4
|
import { getKey } from 'wuchale';
|
|
6
5
|
import { MixedVisitor, nonWhitespaceText } from 'wuchale/adapter-utils';
|
|
7
6
|
import { parseScript, scriptParseOptionsWithComments, Transformer } from 'wuchale/adapter-vanilla';
|
|
@@ -28,6 +27,7 @@ export class AstroTransformer extends Transformer {
|
|
|
28
27
|
super(content.trim(), filename, index, heuristic, patterns, catalogExpr, rtConf, matchUrl);
|
|
29
28
|
this.byteArray = new Uint8Array(Buffer.from(this.content));
|
|
30
29
|
this.heuristciDetails.insideProgram = false;
|
|
30
|
+
this.mixedVisitor = this.initMixedVisitor();
|
|
31
31
|
}
|
|
32
32
|
_byteOffsetToIndex = (offset) => {
|
|
33
33
|
// this is necessary because offsets come from astro's go parser, which works with bytes
|
|
@@ -82,8 +82,8 @@ export class AstroTransformer extends Transformer {
|
|
|
82
82
|
isComment: node => node.type === 'comment',
|
|
83
83
|
leaveInPlace: node => [''].includes(node.type),
|
|
84
84
|
isExpression: node => node.type === 'expression',
|
|
85
|
-
getTextContent:
|
|
86
|
-
getCommentData:
|
|
85
|
+
getTextContent: node => node.value,
|
|
86
|
+
getCommentData: node => node.value.trim(),
|
|
87
87
|
canHaveChildren: node => nodesWithChildren.includes(node.type),
|
|
88
88
|
visitFunc: (child, inCompoundText) => {
|
|
89
89
|
const inCompoundTextPrev = this.inCompoundText;
|
|
@@ -121,7 +121,7 @@ export class AstroTransformer extends Transformer {
|
|
|
121
121
|
let end = '\n})}';
|
|
122
122
|
if (hasExprs) {
|
|
123
123
|
begin += ',\na: [';
|
|
124
|
-
end =
|
|
124
|
+
end = `]${end}`;
|
|
125
125
|
}
|
|
126
126
|
this.mstr.appendLeft(lastChildEnd, begin);
|
|
127
127
|
this.mstr.appendRight(lastChildEnd, end);
|
|
@@ -151,7 +151,7 @@ export class AstroTransformer extends Transformer {
|
|
|
151
151
|
}
|
|
152
152
|
msgs.push(...this.visitAs(part));
|
|
153
153
|
const { start, end } = this.getRange(part);
|
|
154
|
-
if (end
|
|
154
|
+
if (end === -1)
|
|
155
155
|
console.log(part, node);
|
|
156
156
|
expr += `"${' '.repeat(end - start)}"`;
|
|
157
157
|
}
|
|
@@ -181,7 +181,7 @@ export class AstroTransformer extends Transformer {
|
|
|
181
181
|
return msgs;
|
|
182
182
|
};
|
|
183
183
|
visitcomponent = (node) => this.visitelement(node);
|
|
184
|
-
|
|
184
|
+
'visitcustom-element' = (node) => this.visitelement(node);
|
|
185
185
|
visitattribute = (node) => {
|
|
186
186
|
const heurBase = {
|
|
187
187
|
scope: 'attribute',
|
|
@@ -242,8 +242,6 @@ export class AstroTransformer extends Transformer {
|
|
|
242
242
|
visitAs = (node) => this.visit(node);
|
|
243
243
|
transformAs = async () => {
|
|
244
244
|
const { ast } = await parse(this.content);
|
|
245
|
-
this.mstr = new MagicString(this.content);
|
|
246
|
-
this.mixedVisitor = this.initMixedVisitor();
|
|
247
245
|
const msgs = this.visitAs(ast);
|
|
248
246
|
if (this.frontMatterStart == null) {
|
|
249
247
|
this.mstr.appendLeft(0, '---\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/astro",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Wuchale i18n adapter for Astro files",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -48,15 +48,16 @@
|
|
|
48
48
|
"author": "K1DV5",
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@astrojs/compiler": "^
|
|
51
|
+
"@astrojs/compiler": "^3",
|
|
52
52
|
"@sveltejs/acorn-typescript": "^1.0.9",
|
|
53
53
|
"acorn": "^8.16.0",
|
|
54
54
|
"magic-string": "^0.30.21",
|
|
55
|
-
"wuchale": "^0.
|
|
55
|
+
"wuchale": "^0.23.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/estree-jsx": "^1.0.5",
|
|
59
|
-
"
|
|
59
|
+
"@types/node": "~24.12.2",
|
|
60
|
+
"typescript": "^6.0.3"
|
|
60
61
|
},
|
|
61
62
|
"type": "module"
|
|
62
63
|
}
|
package/src/loaders/astro.js
CHANGED
|
@@ -6,7 +6,7 @@ import { loadCatalog, loadIDs } from '${PROXY_SYNC}'
|
|
|
6
6
|
|
|
7
7
|
const key = '${KEY}'
|
|
8
8
|
|
|
9
|
-
export { loadCatalog, loadIDs
|
|
9
|
+
export { key, loadCatalog, loadIDs }
|
|
10
10
|
|
|
11
11
|
// For non-reactive server-side rendering
|
|
12
12
|
export const getRuntime = (/** @type {string} */ loadID) => currentRuntime(key, loadID)
|