Skip to content
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
23 changes: 20 additions & 3 deletions documentation/docs/build/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ next:

# Configuration

The jitar build process is configured using a `jitar.json` file. This file is optional and defines the location of the `source`, `target`, `segments`, and `resources` folders. These values are used to split the application in separate deployable bundles and create the necessary configuration files for the jitar runtime.
The jitar build process and runtime environment is configured using a JSON file. This file is optional and can be added to a project at any time.

## Jitar configuration file

The `jitar.json` file is a JSON file that contains the following properties:
By default, Jitar looks for a `jitar.json` file in the project's root directory, but you can use a different filename and specify it when running the CLI.

A basic configuration contains the following properties:

```json
{
Expand All @@ -37,7 +39,7 @@ The configuration also supports environment variables. They can be used by wrapp
```
:::

There are four properties in the configuration file:
There are four main properties in the configuration file:
* `source` - the location of the source files (default `./src`).
* `target` - the location of the target files (default `./dist`).
* `segments` - the location of the segment configuration files (default `./segments`).
Expand All @@ -50,3 +52,18 @@ For a TypeScript project, the `source` folder should be the target folder after
::: warning IMPORTANT
The build process deletes the files in the `target` folder during the build process. Make sure that it doesn't point to the `src` folder.
:::

## Specific build options

Additionally, the configuration supports specific build options.

```json
{
"source": "./src",
"build": {
"ignore": ["app/**/*"]
}
}
```

* `build.ignore` - list of glob patterns, relative to the source folder, specifying files that should be ignored during the build (default `[]`).
44 changes: 22 additions & 22 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jitar-monorepo",
"version": "0.11.1",
"version": "0.11.2",
"private": true,
"description": "Monorepo configuration for Jitar.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/analysis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jitar/analysis",
"version": "0.11.1",
"version": "0.11.2",
"description": "Application analysis library for the Jitar runtime.",
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jitar/build",
"version": "0.11.1",
"version": "0.11.2",
"description": "Application building library for the Jitar runtime.",
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
"license": "MIT",
Expand Down
15 changes: 8 additions & 7 deletions packages/build/src/BuildHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export default class BuildHelper
const resources = this.#fileHelper.makePathAbsolute(configuration.resources, configuration.meta.root);
const segments = this.#fileHelper.makePathAbsolute(configuration.segments, configuration.meta.root);

const sourceFileManager = new LocalFileManager(source);
const targetFileManager = new LocalFileManager(target);
const resourceFileManager = new LocalFileManager(resources);
const segmentFileManager = new LocalFileManager(segments);

this.#fileManager = new ProjectFileManager(sourceFileManager, targetFileManager, resourceFileManager, segmentFileManager);
this.#fileManager = new ProjectFileManager(
new LocalFileManager(source),
new LocalFileManager(target),
new LocalFileManager(resources),
new LocalFileManager(segments),
configuration.build.ignore
);

this.#applicationReader = new ApplicationReader(this.#fileManager);
}
Expand All @@ -42,7 +43,7 @@ export default class BuildHelper
const resourceFileManager = this.#fileManager.resource;
const segmentFileManager = this.#fileManager.segment;

const moduleFiles = await sourceFileManager.filter(Files.MODULE_PATTERN);
const moduleFiles = await sourceFileManager.filterWithIgnores(Files.MODULE_PATTERN, this.#fileManager.sourceIgnores);
const resourceFiles = await resourceFileManager.filter(Files.RESOURCE_PATTERN);
const segmentFiles = await segmentFileManager.filter(Files.SEGMENT_PATTERN);

Expand Down
15 changes: 8 additions & 7 deletions packages/build/src/BuildManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ export default class BuildManager
const resources = this.#fileHelper.makePathAbsolute(configuration.resources, configuration.meta.root);
const segments = this.#fileHelper.makePathAbsolute(configuration.segments, configuration.meta.root);

const sourceFileManager = new LocalFileManager(source);
const targetFileManager = new LocalFileManager(target);
const resourceFileManager = new LocalFileManager(resources);
const segmentFileManager = new LocalFileManager(segments);

this.#fileManager = new ProjectFileManager(sourceFileManager, targetFileManager, resourceFileManager, segmentFileManager);
this.#fileManager = new ProjectFileManager(
new LocalFileManager(source),
new LocalFileManager(target),
new LocalFileManager(resources),
new LocalFileManager(segments),
configuration.build.ignore
);

this.#applicationReader = new ApplicationReader(this.#fileManager);
this.#applicationBuilder = new ApplicationBuilder(this.#fileManager, this.#logger);
Expand All @@ -46,7 +47,7 @@ export default class BuildManager
const resourceFileManager = this.#fileManager.resource;
const segmentFileManager = this.#fileManager.segment;

const moduleFiles = await sourceFileManager.filter(Files.MODULE_PATTERN);
const moduleFiles = await sourceFileManager.filterWithIgnores(Files.MODULE_PATTERN, this.#fileManager.sourceIgnores);
const resourceFiles = await resourceFileManager.filter(Files.RESOURCE_PATTERN);
const segmentFiles = await segmentFileManager.filter(Files.SEGMENT_PATTERN);

Expand Down
6 changes: 5 additions & 1 deletion packages/build/src/ProjectFileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export default class ProjectFileManager
readonly #target: FileManager;
readonly #resource: FileManager;
readonly #segment: FileManager;
readonly #sourceIgnores: string[];

constructor(source: FileManager, target: FileManager, resource: FileManager, segment: FileManager)
constructor(source: FileManager, target: FileManager, resource: FileManager, segment: FileManager, sourceIgnores: string[])
{
this.#source = source;
this.#target = target;
this.#resource = resource;
this.#segment = segment;
this.#sourceIgnores = sourceIgnores;
}

get source() { return this.#source; }
Expand All @@ -23,4 +25,6 @@ export default class ProjectFileManager
get resource() { return this.#resource; }

get segment() { return this.#segment; }

get sourceIgnores() { return this.#sourceIgnores; }
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jitar/cli",
"version": "0.11.1",
"version": "0.11.2",
"description": "CLI tool for the Jitar runtime.",
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/configuration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jitar/configuration",
"version": "0.11.1",
"version": "0.11.2",
"description": "Configuration library for the Jitar runtime.",
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions packages/configuration/src/runtime/ConfigurationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class ConfigurationBuilder
configuration.target ??= DefaultValues.TARGET;
configuration.segments ??= DefaultValues.SEGMENTS;
configuration.resources ??= DefaultValues.RESOURCES;
configuration.build ??= DefaultValues.BUILD;
configuration.build.ignore ??= DefaultValues.BUILD_IGNORE;
Comment on lines +34 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid sharing mutable defaults across builds.

Line 34 and Line 35 assign shared object/array references from DefaultValues. If configuration.build.ignore is mutated later, subsequent build() calls can inherit stale ignore patterns.

Suggested fix
-        configuration.build ??= DefaultValues.BUILD;
-        configuration.build.ignore ??= DefaultValues.BUILD_IGNORE;
+        configuration.build ??= { ignore: [...DefaultValues.BUILD_IGNORE] };
+        configuration.build.ignore ??= [...DefaultValues.BUILD_IGNORE];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
configuration.build ??= DefaultValues.BUILD;
configuration.build.ignore ??= DefaultValues.BUILD_IGNORE;
configuration.build ??= { ...DefaultValues.BUILD, ignore: [...DefaultValues.BUILD_IGNORE] };
configuration.build.ignore ??= [...DefaultValues.BUILD_IGNORE];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/configuration/src/runtime/ConfigurationBuilder.ts` around lines 34 -
35, The code at lines 34-35 in ConfigurationBuilder.ts assigns shared references
from DefaultValues.BUILD and DefaultValues.BUILD_IGNORE directly to the
configuration object. To prevent mutations in one build from affecting
subsequent builds, create independent copies of these default objects instead of
reusing the shared references. When assigning to configuration.build and
configuration.build.ignore, use a cloning or spreading mechanism to ensure each
configuration instance gets its own copy of the default values rather than a
shared reference.


configuration.meta =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ type RuntimeConfiguration =
segments: string;
resources: string;

build:
{
ignore: string[];
}

meta:
{
root: string;
Expand All @@ -23,15 +28,25 @@ const DefaultValues =
SOURCE: './src',
TARGET: './dist',
SEGMENTS: './segments',
RESOURCES: './resources'
} as const;
RESOURCES: './resources',
BUILD: { ignore: [] },
BUILD_IGNORE: []
};

const validationScheme: ValidationScheme =
{
source: { type: 'string', required: false },
target: { type: 'string', required: false },
segments: { type: 'string', required: false },
resources: { type: 'string', required: false }
resources: { type: 'string', required: false },

build: {
type: 'group',
fields: {
ignore: { type: 'list', items: { type: 'string' }, required: false },
},
required: false
}
} as const;

export { DefaultValues, validationScheme };
Loading
Loading