jac-client 0.2.3__py3-none-any.whl → 0.2.8__py3-none-any.whl
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.
- jac_client/examples/all-in-one/app.jac +494 -347
- jac_client/examples/all-in-one/assets/workers/worker.py +5 -0
- jac_client/examples/all-in-one/button.jac +1 -1
- jac_client/examples/all-in-one/components/CategoryFilter.jac +35 -0
- jac_client/examples/all-in-one/components/Header.jac +13 -0
- jac_client/examples/all-in-one/components/ProfitOverview.jac +50 -0
- jac_client/examples/all-in-one/components/Summary.jac +53 -0
- jac_client/examples/all-in-one/components/TransactionForm.jac +158 -0
- jac_client/examples/all-in-one/components/TransactionItem.jac +55 -0
- jac_client/examples/all-in-one/components/TransactionList.jac +37 -0
- jac_client/examples/all-in-one/components/button.jac +1 -1
- jac_client/examples/all-in-one/components/navigation.jac +132 -0
- jac_client/examples/all-in-one/constants/categories.jac +37 -0
- jac_client/examples/all-in-one/constants/clients.jac +13 -0
- jac_client/examples/all-in-one/context/BudgetContext.jac +28 -0
- jac_client/examples/all-in-one/hooks/useBudget.jac +116 -0
- jac_client/examples/all-in-one/hooks/useLocalStorage.jac +36 -0
- jac_client/examples/all-in-one/pages/BudgetPlanner.cl.jac +70 -0
- jac_client/examples/all-in-one/pages/BudgetPlanner.jac +126 -0
- jac_client/examples/all-in-one/pages/FeaturesTest.cl.jac +552 -0
- jac_client/examples/all-in-one/pages/FeaturesTest.jac +126 -0
- jac_client/examples/all-in-one/pages/LandingPage.jac +101 -0
- jac_client/examples/all-in-one/pages/loginPage.jac +132 -0
- jac_client/examples/all-in-one/pages/nestedDemo.jac +61 -0
- jac_client/examples/all-in-one/pages/notFound.jac +24 -0
- jac_client/examples/all-in-one/pages/signupPage.jac +133 -0
- jac_client/examples/all-in-one/utils/formatters.jac +52 -0
- jac_client/examples/asset-serving/css-with-image/{app.jac → src/app.jac} +4 -4
- jac_client/examples/asset-serving/image-asset/{app.jac → src/app.jac} +4 -4
- jac_client/examples/asset-serving/import-alias/{app.jac → src/app.jac} +5 -5
- jac_client/examples/basic/{app.jac → src/app.jac} +4 -4
- jac_client/examples/basic-auth/src/app.jac +371 -0
- jac_client/examples/basic-auth-with-router/{app.jac → src/app.jac} +28 -28
- jac_client/examples/basic-full-stack/{app.jac → src/app.jac} +166 -127
- jac_client/examples/css-styling/js-styling/{app.jac → src/app.jac} +7 -7
- jac_client/examples/css-styling/material-ui/{app.jac → src/app.jac} +6 -6
- jac_client/examples/css-styling/pure-css/{app.jac → src/app.jac} +7 -7
- jac_client/examples/css-styling/sass-example/{app.jac → src/app.jac} +7 -7
- jac_client/examples/css-styling/styled-components/{app.jac → src/app.jac} +6 -6
- jac_client/examples/css-styling/tailwind-example/{app.jac → src/app.jac} +7 -7
- jac_client/examples/full-stack-with-auth/{app.jac → src/app.jac} +47 -47
- jac_client/examples/little-x/{app.jac → src/app.jac} +27 -32
- jac_client/examples/little-x/src/submit-button.jac +16 -0
- jac_client/examples/nested-folders/nested-advance/{ButtonRoot.jac → src/ButtonRoot.jac} +1 -1
- jac_client/examples/nested-folders/nested-advance/{app.jac → src/app.jac} +1 -1
- jac_client/examples/nested-folders/nested-advance/{level1 → src/level1}/ButtonSecondL.jac +1 -1
- jac_client/examples/nested-folders/nested-advance/{level1 → src/level1}/Card.jac +1 -1
- jac_client/examples/nested-folders/nested-advance/{level1 → src/level1}/level2/ButtonThirdL.jac +1 -1
- jac_client/examples/nested-folders/nested-basic/{app.jac → src/app.jac} +2 -2
- jac_client/examples/nested-folders/nested-basic/{button.jac → src/button.jac} +1 -1
- jac_client/examples/nested-folders/nested-basic/{components → src/components}/button.jac +1 -1
- jac_client/examples/ts-support/src/app.jac +35 -0
- jac_client/examples/with-router/{app.jac → src/app.jac} +15 -15
- jac_client/plugin/cli.jac +504 -0
- jac_client/plugin/client.jac +45 -0
- jac_client/plugin/client_runtime.cl.jac +42 -0
- jac_client/plugin/impl/client.impl.jac +193 -0
- jac_client/plugin/impl/client_runtime.impl.jac +195 -0
- jac_client/plugin/impl/vite_client_bundle.impl.jac +72 -0
- jac_client/plugin/plugin_config.jac +195 -0
- jac_client/plugin/src/__init__.jac +20 -0
- jac_client/plugin/src/asset_processor.jac +33 -0
- jac_client/plugin/src/babel_processor.jac +18 -0
- jac_client/plugin/src/compiler.jac +67 -0
- jac_client/plugin/src/config_loader.jac +32 -0
- jac_client/plugin/src/impl/asset_processor.impl.jac +127 -0
- jac_client/plugin/src/impl/babel_processor.impl.jac +89 -0
- jac_client/plugin/src/impl/compiler.impl.jac +288 -0
- jac_client/plugin/src/impl/config_loader.impl.jac +119 -0
- jac_client/plugin/src/impl/import_processor.impl.jac +33 -0
- jac_client/plugin/src/impl/jac_to_js.impl.jac +41 -0
- jac_client/plugin/src/impl/package_installer.impl.jac +105 -0
- jac_client/plugin/src/impl/vite_bundler.impl.jac +626 -0
- jac_client/plugin/src/import_processor.jac +19 -0
- jac_client/plugin/src/jac_to_js.jac +35 -0
- jac_client/plugin/src/package_installer.jac +26 -0
- jac_client/plugin/src/vite_bundler.jac +44 -0
- jac_client/plugin/vite_client_bundle.jac +31 -0
- jac_client/tests/conftest.py +283 -0
- jac_client/tests/fixtures/basic-app/app.jac +2 -2
- jac_client/tests/fixtures/cl_file/app.cl.jac +2 -2
- jac_client/tests/fixtures/client_app_with_antd/app.jac +1 -1
- jac_client/tests/fixtures/js_import/app.jac +5 -5
- jac_client/tests/fixtures/spawn_test/app.jac +15 -18
- jac_client/tests/fixtures/with-ts/app.jac +35 -0
- jac_client/tests/test_cli.py +811 -0
- jac_client/tests/test_it.py +592 -97
- {jac_client-0.2.3.dist-info → jac_client-0.2.8.dist-info}/METADATA +41 -34
- jac_client-0.2.8.dist-info/RECORD +97 -0
- {jac_client-0.2.3.dist-info → jac_client-0.2.8.dist-info}/WHEEL +2 -1
- jac_client-0.2.8.dist-info/entry_points.txt +4 -0
- jac_client-0.2.8.dist-info/top_level.txt +1 -0
- jac_client/docs/README.md +0 -689
- jac_client/docs/advanced-state.md +0 -1265
- jac_client/docs/asset-serving/intro.md +0 -209
- jac_client/docs/assets/pipe_line-v2.svg +0 -32
- jac_client/docs/assets/pipe_line.png +0 -0
- jac_client/docs/file-system/app.jac.md +0 -121
- jac_client/docs/file-system/backend-frontend.md +0 -217
- jac_client/docs/file-system/intro.md +0 -72
- jac_client/docs/file-system/nested-imports.md +0 -348
- jac_client/docs/guide-example/intro.md +0 -115
- jac_client/docs/guide-example/step-01-setup.md +0 -270
- jac_client/docs/guide-example/step-02-components.md +0 -416
- jac_client/docs/guide-example/step-03-styling.md +0 -478
- jac_client/docs/guide-example/step-04-todo-ui.md +0 -477
- jac_client/docs/guide-example/step-05-local-state.md +0 -530
- jac_client/docs/guide-example/step-06-events.md +0 -749
- jac_client/docs/guide-example/step-07-effects.md +0 -468
- jac_client/docs/guide-example/step-08-walkers.md +0 -534
- jac_client/docs/guide-example/step-09-authentication.md +0 -586
- jac_client/docs/guide-example/step-10-routing.md +0 -539
- jac_client/docs/guide-example/step-11-final.md +0 -963
- jac_client/docs/imports.md +0 -1141
- jac_client/docs/lifecycle-hooks.md +0 -773
- jac_client/docs/routing.md +0 -659
- jac_client/docs/styling/intro.md +0 -249
- jac_client/docs/styling/js-styling.md +0 -367
- jac_client/docs/styling/material-ui.md +0 -341
- jac_client/docs/styling/pure-css.md +0 -299
- jac_client/docs/styling/sass.md +0 -403
- jac_client/docs/styling/styled-components.md +0 -395
- jac_client/docs/styling/tailwind.md +0 -298
- jac_client/examples/all-in-one/.babelrc +0 -9
- jac_client/examples/all-in-one/README.md +0 -16
- jac_client/examples/all-in-one/assets/burger.png +0 -0
- jac_client/examples/all-in-one/package.json +0 -29
- jac_client/examples/all-in-one/styles.css +0 -26
- jac_client/examples/all-in-one/vite.config.js +0 -28
- jac_client/examples/asset-serving/css-with-image/.babelrc +0 -9
- jac_client/examples/asset-serving/css-with-image/README.md +0 -91
- jac_client/examples/asset-serving/css-with-image/assets/burger.png +0 -0
- jac_client/examples/asset-serving/css-with-image/package.json +0 -28
- jac_client/examples/asset-serving/css-with-image/styles.css +0 -26
- jac_client/examples/asset-serving/css-with-image/vite.config.js +0 -28
- jac_client/examples/asset-serving/image-asset/.babelrc +0 -9
- jac_client/examples/asset-serving/image-asset/README.md +0 -119
- jac_client/examples/asset-serving/image-asset/assets/burger.png +0 -0
- jac_client/examples/asset-serving/image-asset/package.json +0 -28
- jac_client/examples/asset-serving/image-asset/styles.css +0 -26
- jac_client/examples/asset-serving/image-asset/vite.config.js +0 -28
- jac_client/examples/asset-serving/import-alias/.babelrc +0 -9
- jac_client/examples/asset-serving/import-alias/README.md +0 -83
- jac_client/examples/asset-serving/import-alias/assets/burger.png +0 -0
- jac_client/examples/asset-serving/import-alias/package.json +0 -28
- jac_client/examples/asset-serving/import-alias/vite.config.js +0 -28
- jac_client/examples/basic/.babelrc +0 -9
- jac_client/examples/basic/README.md +0 -16
- jac_client/examples/basic/package.json +0 -27
- jac_client/examples/basic/vite.config.js +0 -27
- jac_client/examples/basic-auth/.babelrc +0 -9
- jac_client/examples/basic-auth/README.md +0 -16
- jac_client/examples/basic-auth/app.jac +0 -308
- jac_client/examples/basic-auth/package.json +0 -27
- jac_client/examples/basic-auth/vite.config.js +0 -27
- jac_client/examples/basic-auth-with-router/.babelrc +0 -9
- jac_client/examples/basic-auth-with-router/README.md +0 -60
- jac_client/examples/basic-auth-with-router/package.json +0 -28
- jac_client/examples/basic-auth-with-router/vite.config.js +0 -27
- jac_client/examples/basic-full-stack/.babelrc +0 -9
- jac_client/examples/basic-full-stack/README.md +0 -18
- jac_client/examples/basic-full-stack/package.json +0 -28
- jac_client/examples/basic-full-stack/vite.config.js +0 -27
- jac_client/examples/css-styling/js-styling/.babelrc +0 -9
- jac_client/examples/css-styling/js-styling/README.md +0 -183
- jac_client/examples/css-styling/js-styling/package.json +0 -28
- jac_client/examples/css-styling/js-styling/styles.js +0 -100
- jac_client/examples/css-styling/js-styling/vite.config.js +0 -27
- jac_client/examples/css-styling/material-ui/.babelrc +0 -9
- jac_client/examples/css-styling/material-ui/README.md +0 -16
- jac_client/examples/css-styling/material-ui/package.json +0 -32
- jac_client/examples/css-styling/material-ui/vite.config.js +0 -27
- jac_client/examples/css-styling/pure-css/.babelrc +0 -9
- jac_client/examples/css-styling/pure-css/README.md +0 -16
- jac_client/examples/css-styling/pure-css/package.json +0 -28
- jac_client/examples/css-styling/pure-css/styles.css +0 -111
- jac_client/examples/css-styling/pure-css/vite.config.js +0 -27
- jac_client/examples/css-styling/sass-example/.babelrc +0 -9
- jac_client/examples/css-styling/sass-example/README.md +0 -16
- jac_client/examples/css-styling/sass-example/package.json +0 -29
- jac_client/examples/css-styling/sass-example/styles.scss +0 -153
- jac_client/examples/css-styling/sass-example/vite.config.js +0 -27
- jac_client/examples/css-styling/styled-components/.babelrc +0 -9
- jac_client/examples/css-styling/styled-components/README.md +0 -16
- jac_client/examples/css-styling/styled-components/package.json +0 -29
- jac_client/examples/css-styling/styled-components/styled.js +0 -90
- jac_client/examples/css-styling/styled-components/vite.config.js +0 -27
- jac_client/examples/css-styling/tailwind-example/.babelrc +0 -9
- jac_client/examples/css-styling/tailwind-example/README.md +0 -16
- jac_client/examples/css-styling/tailwind-example/global.css +0 -1
- jac_client/examples/css-styling/tailwind-example/package.json +0 -30
- jac_client/examples/css-styling/tailwind-example/vite.config.js +0 -29
- jac_client/examples/full-stack-with-auth/.babelrc +0 -9
- jac_client/examples/full-stack-with-auth/README.md +0 -16
- jac_client/examples/full-stack-with-auth/package.json +0 -28
- jac_client/examples/full-stack-with-auth/vite.config.js +0 -29
- jac_client/examples/little-x/package.json +0 -23
- jac_client/examples/little-x/submit-button.jac +0 -8
- jac_client/examples/nested-folders/nested-advance/.babelrc +0 -9
- jac_client/examples/nested-folders/nested-advance/README.md +0 -77
- jac_client/examples/nested-folders/nested-advance/package.json +0 -29
- jac_client/examples/nested-folders/nested-advance/vite.config.js +0 -28
- jac_client/examples/nested-folders/nested-basic/.babelrc +0 -9
- jac_client/examples/nested-folders/nested-basic/README.md +0 -183
- jac_client/examples/nested-folders/nested-basic/app.js +0 -7
- jac_client/examples/nested-folders/nested-basic/package.json +0 -28
- jac_client/examples/nested-folders/nested-basic/vite.config.js +0 -27
- jac_client/examples/with-router/.babelrc +0 -9
- jac_client/examples/with-router/README.md +0 -17
- jac_client/examples/with-router/package.json +0 -28
- jac_client/examples/with-router/vite.config.js +0 -27
- jac_client/plugin/cli.py +0 -244
- jac_client/plugin/client.py +0 -152
- jac_client/plugin/client_runtime.jac +0 -234
- jac_client/plugin/vite_client_bundle.py +0 -503
- jac_client/tests/fixtures/js_import/utils.js +0 -21
- jac_client/tests/fixtures/package-lock.json +0 -329
- jac_client/tests/fixtures/package.json +0 -11
- jac_client/tests/test_asset_examples.py +0 -322
- jac_client/tests/test_cl.py +0 -530
- jac_client/tests/test_create_jac_app.py +0 -131
- jac_client/tests/test_nested_file.py +0 -374
- jac_client-0.2.3.dist-info/RECORD +0 -171
- jac_client-0.2.3.dist-info/entry_points.txt +0 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Implementation of Jac Client configuration loader.
|
|
2
|
+
|
|
3
|
+
This module provides the implementation for JacClientConfig, which inherits
|
|
4
|
+
from PluginConfigBase for common configuration loading functionality.
|
|
5
|
+
|
|
6
|
+
The base class handles: init, get_jac_config, get_section.
|
|
7
|
+
This file implements plugin-specific methods including a custom load()
|
|
8
|
+
that combines plugin config with npm dependencies.
|
|
9
|
+
"""
|
|
10
|
+
import from pathlib { Path }
|
|
11
|
+
import from typing { Any }
|
|
12
|
+
import from jaclang.project.plugin_config { deep_merge }
|
|
13
|
+
|
|
14
|
+
"""Get the plugin section name for client."""
|
|
15
|
+
impl JacClientConfig.get_plugin_name(self: JacClientConfig) -> str {
|
|
16
|
+
return "client";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
"""Get default configuration structure for client."""
|
|
20
|
+
impl JacClientConfig.get_default_config(self: JacClientConfig) -> dict[str, Any] {
|
|
21
|
+
return {
|
|
22
|
+
'vite': {
|
|
23
|
+
'plugins': [],
|
|
24
|
+
'lib_imports': [],
|
|
25
|
+
'build': {},
|
|
26
|
+
'server': {},
|
|
27
|
+
'resolve': {}
|
|
28
|
+
},
|
|
29
|
+
'ts': {'compilerOptions': {}, 'include': [], 'exclude': []},
|
|
30
|
+
'package': {
|
|
31
|
+
'name': '',
|
|
32
|
+
'version': '1.0.0',
|
|
33
|
+
'description': '',
|
|
34
|
+
'dependencies': {},
|
|
35
|
+
'devDependencies': {}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
"""Load configuration from jac.toml, merging with defaults.
|
|
41
|
+
|
|
42
|
+
Overrides base class to also include npm dependencies from [dependencies.npm].
|
|
43
|
+
"""
|
|
44
|
+
impl JacClientConfig.load(self: JacClientConfig) -> dict[str, Any] {
|
|
45
|
+
if self._config is not None {
|
|
46
|
+
return self._config;
|
|
47
|
+
}
|
|
48
|
+
default_config = self.get_default_config();
|
|
49
|
+
jac_config = self.get_jac_config();
|
|
50
|
+
# Get client plugin config from [plugins.client]
|
|
51
|
+
client_config = jac_config.get_plugin_config('client');
|
|
52
|
+
# Get npm dependencies from [dependencies.npm]
|
|
53
|
+
npm_deps = jac_config.get_plugin_deps('npm');
|
|
54
|
+
# Get npm dev dependencies from [dev-dependencies.npm]
|
|
55
|
+
# These are stored in plugin_dependencies["npm"]["dev"] after parsing
|
|
56
|
+
npm_plugin_deps = jac_config.plugin_dependencies.get('npm', {});
|
|
57
|
+
npm_dev_deps = npm_plugin_deps.get('dev', {})
|
|
58
|
+
if isinstance(npm_plugin_deps.get('dev'), dict)
|
|
59
|
+
else {};
|
|
60
|
+
# Build user config in the expected internal format
|
|
61
|
+
user_config: dict[str, Any] = {
|
|
62
|
+
'vite': client_config.get('vite', {}),
|
|
63
|
+
'ts': client_config.get('ts', {}),
|
|
64
|
+
'package': {
|
|
65
|
+
'name': jac_config.project.name,
|
|
66
|
+
'version': jac_config.project.version,
|
|
67
|
+
'description': jac_config.project.description,
|
|
68
|
+
'dependencies': npm_deps,
|
|
69
|
+
'devDependencies': npm_dev_deps
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
self._config = deep_merge(default_config, user_config);
|
|
73
|
+
return self._config;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
"""Get package configuration (npm dependencies)."""
|
|
77
|
+
impl JacClientConfig.get_package_config(self: JacClientConfig) -> dict[str, Any] {
|
|
78
|
+
config = self.load();
|
|
79
|
+
return config.get('package', {});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
"""Get Vite-specific configuration."""
|
|
83
|
+
impl JacClientConfig.get_vite_config(self: JacClientConfig) -> dict[str, Any] {
|
|
84
|
+
config = self.load();
|
|
85
|
+
return config.get('vite', {});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
"""Get TypeScript-specific configuration for tsconfig.json customization."""
|
|
89
|
+
impl JacClientConfig.get_ts_config(self: JacClientConfig) -> dict[str, Any] {
|
|
90
|
+
config = self.load();
|
|
91
|
+
return config.get('ts', {});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
"""Save configuration back to jac.toml using core JacConfig."""
|
|
95
|
+
impl JacClientConfig.save(self: JacClientConfig) -> None {
|
|
96
|
+
jac_config = self.get_jac_config();
|
|
97
|
+
jac_config.save();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
"""Add an npm dependency."""
|
|
101
|
+
impl JacClientConfig.add_dependency(
|
|
102
|
+
self: JacClientConfig, name: str, version: str, is_dev: bool = False
|
|
103
|
+
) -> None {
|
|
104
|
+
jac_config = self.get_jac_config();
|
|
105
|
+
jac_config.add_dependency(name, version, dev=is_dev, dep_type="npm");
|
|
106
|
+
# Invalidate cache
|
|
107
|
+
self.invalidate();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
"""Remove an npm dependency."""
|
|
111
|
+
impl JacClientConfig.remove_dependency(
|
|
112
|
+
self: JacClientConfig, name: str, is_dev: bool = False
|
|
113
|
+
) -> bool {
|
|
114
|
+
jac_config = self.get_jac_config();
|
|
115
|
+
result = jac_config.remove_dependency(name, dev=is_dev, dep_type="npm");
|
|
116
|
+
# Invalidate cache
|
|
117
|
+
self.invalidate();
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Check if an import should be processed (compiled/copied) vs left for Vite."""
|
|
2
|
+
|
|
3
|
+
impl ImportProcessor.should_process_import(
|
|
4
|
+
self: ImportProcessor, import_path: Path
|
|
5
|
+
) -> bool {
|
|
6
|
+
return (import_path.suffix in {'.jac','.js'});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
"""Process client imports for Vite bundling."""
|
|
10
|
+
impl ImportProcessor.process_vite_imports(
|
|
11
|
+
self: ImportProcessor, manifest: (ClientManifest | None), module_path: Path
|
|
12
|
+
) -> list[(Path | None)] {
|
|
13
|
+
imported_js_modules: list[(Path | None)] = [];
|
|
14
|
+
if (manifest and manifest.imports) {
|
|
15
|
+
for (_, import_path) in manifest.imports.items() {
|
|
16
|
+
import_path_obj = Path(import_path);
|
|
17
|
+
if (import_path_obj.suffix == '.js') {
|
|
18
|
+
try {
|
|
19
|
+
imported_js_modules.append(import_path_obj);
|
|
20
|
+
} except FileNotFoundError {
|
|
21
|
+
imported_js_modules.append(None);
|
|
22
|
+
}
|
|
23
|
+
} elif (import_path_obj.suffix == '.jac') {
|
|
24
|
+
try {
|
|
25
|
+
imported_js_modules.append(import_path_obj);
|
|
26
|
+
} except ClientBundleError {
|
|
27
|
+
imported_js_modules.append(None);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return imported_js_modules;
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Add runtime imports to compiled JS code."""
|
|
2
|
+
|
|
3
|
+
impl JacToJSCompiler.add_runtime_imports(self: JacToJSCompiler, js_code: str) -> str {
|
|
4
|
+
jac_jsx_import = 'import {__jacJsx, __jacSpawn} from "@jac-client/utils";';
|
|
5
|
+
return f"{jac_jsx_import}\n{js_code}";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
"""Extract client globals from manifest and module."""
|
|
9
|
+
impl JacToJSCompiler.extract_globals(
|
|
10
|
+
self: JacToJSCompiler, manifest: (ClientManifest | None), module: ModuleType
|
|
11
|
+
) -> dict[str, Any] {
|
|
12
|
+
return self._extract_client_globals(manifest, module);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
"""Extract client exports from manifest."""
|
|
16
|
+
impl JacToJSCompiler.extract_exports(
|
|
17
|
+
self: JacToJSCompiler, manifest: (ClientManifest | None)
|
|
18
|
+
) -> list[str] {
|
|
19
|
+
return self._extract_client_exports(manifest);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
"""Compile a Jac module to JavaScript."""
|
|
23
|
+
impl JacToJSCompiler.compile_module(
|
|
24
|
+
self: JacToJSCompiler, module_path: Path
|
|
25
|
+
) -> tuple[str, (ModuleType | None), (ClientManifest | None)] {
|
|
26
|
+
(module_js, mod) = self._compile_to_js(module_path);
|
|
27
|
+
manifest = mod.gen.client_manifest if mod else None;
|
|
28
|
+
return (module_js, mod, manifest);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
"""Initialize the Jac to JS compiler."""
|
|
32
|
+
impl JacToJSCompiler.init(
|
|
33
|
+
self: JacToJSCompiler,
|
|
34
|
+
compile_to_js_func: Callable[([Path], tuple[(str, (ModuleType | None))])],
|
|
35
|
+
extract_exports_func: Callable[([Any], list[str])],
|
|
36
|
+
extract_globals_func: Callable[([Any, ModuleType], dict[(str, Any)])]
|
|
37
|
+
) {
|
|
38
|
+
self._compile_to_js = compile_to_js_func;
|
|
39
|
+
self._extract_client_exports = extract_exports_func;
|
|
40
|
+
self._extract_client_globals = extract_globals_func;
|
|
41
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""List all installed packages from jac.toml."""
|
|
2
|
+
|
|
3
|
+
impl PackageInstaller.list_packages(
|
|
4
|
+
self: PackageInstaller
|
|
5
|
+
) -> dict[str, dict[str, str]] {
|
|
6
|
+
if not self.config_file.exists() {
|
|
7
|
+
raise ClientBundleError(
|
|
8
|
+
f'jac.toml not found at {self.config_file}. Run "jac init" first.'
|
|
9
|
+
) ;
|
|
10
|
+
}
|
|
11
|
+
config = self.config_loader.load();
|
|
12
|
+
package_config = config.get('package', {});
|
|
13
|
+
return {
|
|
14
|
+
'dependencies': package_config.get('dependencies', {}),
|
|
15
|
+
'devDependencies': package_config.get('devDependencies', {})
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
"""Uninstall a package by removing it from jac.toml."""
|
|
20
|
+
impl PackageInstaller.uninstall_package(
|
|
21
|
+
self: PackageInstaller, package_name: str, is_dev: bool = False
|
|
22
|
+
) -> None {
|
|
23
|
+
if not self.config_file.exists() {
|
|
24
|
+
raise ClientBundleError(
|
|
25
|
+
f'jac.toml not found at {self.config_file}. Run "jac init" first.'
|
|
26
|
+
) ;
|
|
27
|
+
}
|
|
28
|
+
# Remove the dependency using JacClientConfig
|
|
29
|
+
result = self.config_loader.remove_dependency(package_name, is_dev);
|
|
30
|
+
if not result {
|
|
31
|
+
deps_key = 'dev-dependencies' if is_dev else 'dependencies';
|
|
32
|
+
raise ClientBundleError(f'Package "{package_name}" not found in {deps_key}') ;
|
|
33
|
+
}
|
|
34
|
+
# Save the updated config
|
|
35
|
+
self.config_loader.save();
|
|
36
|
+
# Regenerate package.json and run npm install to actually remove the package
|
|
37
|
+
self._regenerate_and_install();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
"""Regenerate package.json from jac.toml and run npm install."""
|
|
41
|
+
impl PackageInstaller._regenerate_and_install(self: PackageInstaller) -> None {
|
|
42
|
+
# Regenerate package.json from updated jac.toml
|
|
43
|
+
bundler = ViteBundler(self.project_dir);
|
|
44
|
+
bundler.create_package_json();
|
|
45
|
+
# Ensure root package.json exists temporarily for npm commands
|
|
46
|
+
bundler._ensure_root_package_json();
|
|
47
|
+
try {
|
|
48
|
+
# Run npm install to actually install the packages
|
|
49
|
+
subprocess.run(
|
|
50
|
+
['npm', 'install'],
|
|
51
|
+
cwd=self.project_dir,
|
|
52
|
+
check=True,
|
|
53
|
+
capture_output=True,
|
|
54
|
+
text=True
|
|
55
|
+
);
|
|
56
|
+
} except subprocess.CalledProcessError as e {
|
|
57
|
+
raise ClientBundleError(f'Failed to install npm packages: {e.stderr}') from e ;
|
|
58
|
+
} except FileNotFoundError {
|
|
59
|
+
raise ClientBundleError(
|
|
60
|
+
'npm command not found. Ensure Node.js and npm are installed.'
|
|
61
|
+
) from None ;
|
|
62
|
+
} finally {
|
|
63
|
+
# Always clean up root package.json and move package-lock.json
|
|
64
|
+
bundler._cleanup_root_package_files();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
"""Install all packages from jac.toml (regenerate package.json and run npm install)."""
|
|
69
|
+
impl PackageInstaller.install_all(self: PackageInstaller) -> None {
|
|
70
|
+
if not self.config_file.exists() {
|
|
71
|
+
raise ClientBundleError(
|
|
72
|
+
f'jac.toml not found at {self.config_file}. Run "jac init" first.'
|
|
73
|
+
) ;
|
|
74
|
+
}
|
|
75
|
+
self._regenerate_and_install();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
"""Install a package by adding it to jac.toml."""
|
|
79
|
+
impl PackageInstaller.install_package(
|
|
80
|
+
self: PackageInstaller,
|
|
81
|
+
package_name: str,
|
|
82
|
+
version: (str | None) = None,
|
|
83
|
+
is_dev: bool = False
|
|
84
|
+
) -> None {
|
|
85
|
+
if not self.config_file.exists() {
|
|
86
|
+
raise ClientBundleError(
|
|
87
|
+
f'jac.toml not found at {self.config_file}. Run "jac init" first.'
|
|
88
|
+
) ;
|
|
89
|
+
}
|
|
90
|
+
# Add package with version (default to latest if not specified)
|
|
91
|
+
package_version = version or 'latest';
|
|
92
|
+
# Use JacClientConfig to add the dependency
|
|
93
|
+
self.config_loader.add_dependency(package_name, package_version, is_dev);
|
|
94
|
+
# Save the updated config
|
|
95
|
+
self.config_loader.save();
|
|
96
|
+
# Regenerate package.json and install the package via npm
|
|
97
|
+
self._regenerate_and_install();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
"""Handles installing npm packages by updating jac.toml."""
|
|
101
|
+
impl PackageInstaller.init(self: PackageInstaller, project_dir: Path) {
|
|
102
|
+
self.project_dir = project_dir;
|
|
103
|
+
self.config_loader = JacClientConfig(project_dir);
|
|
104
|
+
self.config_file = project_dir / 'jac.toml';
|
|
105
|
+
}
|