svelte-django-gettext 1.0.3 → 1.1.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/build.js +26 -9
- package/package.json +9 -56
package/build.js
CHANGED
|
@@ -4,6 +4,11 @@ import { writeFileSync } from 'fs';
|
|
|
4
4
|
*
|
|
5
5
|
* Strings are collected per file, and written to the (.gitignored) `_svelte_extracted_msgids.js`
|
|
6
6
|
* which is parsable by vanilla django `./manage.py makemessages`.
|
|
7
|
+
*
|
|
8
|
+
* This preprocessor only reads the markup, it never rewrites it. It still has to return the
|
|
9
|
+
* content together with an identity sourcemap: a svelte preprocessor returning `undefined` is
|
|
10
|
+
* treated as "transformed, but no sourcemap available" by the build tooling, which makes
|
|
11
|
+
* bundlers (vite >= 8.3) emit SOURCEMAP_BROKEN warnings and degrades sourcemaps downstream.
|
|
7
12
|
*/
|
|
8
13
|
const GETTEXT_REGEXP = /((n|p)?gettext\(.*?\))/g;
|
|
9
14
|
const extracts = {};
|
|
@@ -22,13 +27,25 @@ export function writeGettextExtracts(extractsFile = '_svelte_django_extracted_me
|
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export async function gettextStringExtractor({ content, filename }) {
|
|
25
|
-
if (content.indexOf('gettext')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
30
|
+
if (content.indexOf('gettext') !== -1) {
|
|
31
|
+
let fileExtracts = content.match(GETTEXT_REGEXP);
|
|
32
|
+
if (fileExtracts !== null) {
|
|
33
|
+
extracts[filename] = fileExtracts.map((x) => x.replace(', true)', ')') + ';');
|
|
34
|
+
}
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
36
|
+
|
|
37
|
+
// Content is returned unchanged, so an empty mappings string is a valid identity sourcemap.
|
|
38
|
+
return { code: content, map: identitySourcemap(filename) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* An identity sourcemap for an unmodified file: every position maps to itself, which is what
|
|
42
|
+
* an empty `mappings` string means. `names`/`sourcesContent` are left empty deliberately.
|
|
43
|
+
*/
|
|
44
|
+
function identitySourcemap(filename) {
|
|
45
|
+
return {
|
|
46
|
+
version: 3,
|
|
47
|
+
sources: [filename],
|
|
48
|
+
names: [],
|
|
49
|
+
mappings: '',
|
|
50
|
+
};
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-django-gettext",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Use django gettext in Svelte",
|
|
5
5
|
"author": "Jan Pieter Waagmeester",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "vitest",
|
|
11
|
-
"eslint": "eslint
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"eslint": "eslint --fix .",
|
|
12
|
+
"test:watch": "vitest"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
14
15
|
"Svelte",
|
|
@@ -26,58 +27,10 @@
|
|
|
26
27
|
"README.md"
|
|
27
28
|
],
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"jest": {
|
|
35
|
-
"testEnvironment": "jsdom"
|
|
36
|
-
},
|
|
37
|
-
"eslintConfig": {
|
|
38
|
-
"env": {
|
|
39
|
-
"browser": true,
|
|
40
|
-
"es2021": true
|
|
41
|
-
},
|
|
42
|
-
"extends": "eslint:recommended",
|
|
43
|
-
"parserOptions": {
|
|
44
|
-
"ecmaVersion": 13,
|
|
45
|
-
"sourceType": "module"
|
|
46
|
-
},
|
|
47
|
-
"plugins": [
|
|
48
|
-
"import"
|
|
49
|
-
],
|
|
50
|
-
"rules": {
|
|
51
|
-
"indent": [
|
|
52
|
-
"error",
|
|
53
|
-
4,
|
|
54
|
-
{
|
|
55
|
-
"SwitchCase": 1
|
|
56
|
-
}
|
|
57
|
-
],
|
|
58
|
-
"quotes": [
|
|
59
|
-
"error",
|
|
60
|
-
"single"
|
|
61
|
-
],
|
|
62
|
-
"import/order": [
|
|
63
|
-
"error",
|
|
64
|
-
{
|
|
65
|
-
"groups": [
|
|
66
|
-
"builtin",
|
|
67
|
-
"external",
|
|
68
|
-
"internal",
|
|
69
|
-
[
|
|
70
|
-
"parent",
|
|
71
|
-
"sibling"
|
|
72
|
-
]
|
|
73
|
-
],
|
|
74
|
-
"newlines-between": "always",
|
|
75
|
-
"alphabetize": {
|
|
76
|
-
"order": "asc",
|
|
77
|
-
"caseInsensitive": true
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
]
|
|
81
|
-
}
|
|
30
|
+
"@eslint/js": "^10.0.1",
|
|
31
|
+
"eslint": "^10.10.0",
|
|
32
|
+
"globals": "^17.12.0",
|
|
33
|
+
"jsdom": "^30.1.0",
|
|
34
|
+
"vitest": "^5.0.1"
|
|
82
35
|
}
|
|
83
36
|
}
|