@xpack/xpm-lib 3.0.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/LICENSE +21 -0
- package/README.md +223 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chmod-recursive.d.ts +7 -0
- package/dist/lib/chmod-recursive.d.ts.map +1 -0
- package/dist/lib/chmod-recursive.js +81 -0
- package/dist/lib/chmod-recursive.js.map +1 -0
- package/dist/lib/errors.d.ts +11 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +26 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/functions/chmod-recursive.d.ts +7 -0
- package/dist/lib/functions/chmod-recursive.d.ts.map +1 -0
- package/dist/lib/functions/chmod-recursive.js +81 -0
- package/dist/lib/functions/chmod-recursive.js.map +1 -0
- package/dist/lib/functions/perform-substitutions.d.ts +20 -0
- package/dist/lib/functions/perform-substitutions.d.ts.map +1 -0
- package/dist/lib/functions/perform-substitutions.js +85 -0
- package/dist/lib/functions/perform-substitutions.js.map +1 -0
- package/dist/lib/functions/utils.d.ts +30 -0
- package/dist/lib/functions/utils.d.ts.map +1 -0
- package/dist/lib/functions/utils.js +70 -0
- package/dist/lib/functions/utils.js.map +1 -0
- package/dist/lib/init-template-base.d.ts +46 -0
- package/dist/lib/init-template-base.d.ts.map +1 -0
- package/dist/lib/init-template-base.js +275 -0
- package/dist/lib/init-template-base.js.map +1 -0
- package/dist/lib/liquid-actions.d.ts +32 -0
- package/dist/lib/liquid-actions.d.ts.map +1 -0
- package/dist/lib/liquid-actions.js +113 -0
- package/dist/lib/liquid-actions.js.map +1 -0
- package/dist/lib/liquid-build-configurations.d.ts +49 -0
- package/dist/lib/liquid-build-configurations.d.ts.map +1 -0
- package/dist/lib/liquid-build-configurations.js +267 -0
- package/dist/lib/liquid-build-configurations.js.map +1 -0
- package/dist/lib/liquid-drop.d.ts +13 -0
- package/dist/lib/liquid-drop.d.ts.map +1 -0
- package/dist/lib/liquid-drop.js +56 -0
- package/dist/lib/liquid-drop.js.map +1 -0
- package/dist/lib/liquid-engine.d.ts +5 -0
- package/dist/lib/liquid-engine.d.ts.map +1 -0
- package/dist/lib/liquid-engine.js +85 -0
- package/dist/lib/liquid-engine.js.map +1 -0
- package/dist/lib/liquid-package.d.ts +17 -0
- package/dist/lib/liquid-package.d.ts.map +1 -0
- package/dist/lib/liquid-package.js +70 -0
- package/dist/lib/liquid-package.js.map +1 -0
- package/dist/lib/package.d.ts +66 -0
- package/dist/lib/package.d.ts.map +1 -0
- package/dist/lib/package.js +700 -0
- package/dist/lib/package.js.map +1 -0
- package/dist/lib/perform-substitutions.d.ts +20 -0
- package/dist/lib/perform-substitutions.d.ts.map +1 -0
- package/dist/lib/perform-substitutions.js +85 -0
- package/dist/lib/perform-substitutions.js.map +1 -0
- package/dist/lib/policies.d.ts +13 -0
- package/dist/lib/policies.d.ts.map +1 -0
- package/dist/lib/policies.js +31 -0
- package/dist/lib/policies.js.map +1 -0
- package/dist/lib/substitutions-variables.d.ts +117 -0
- package/dist/lib/substitutions-variables.d.ts.map +1 -0
- package/dist/lib/substitutions-variables.js +51 -0
- package/dist/lib/substitutions-variables.js.map +1 -0
- package/dist/lib/types.d.ts +70 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +13 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +30 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +70 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +102 -0
- package/src/README.md +10 -0
- package/src/index.ts +35 -0
- package/src/lib/errors.ts +29 -0
- package/src/lib/functions/chmod-recursive.ts +103 -0
- package/src/lib/functions/perform-substitutions.ts +116 -0
- package/src/lib/functions/utils.ts +88 -0
- package/src/lib/init-template-base.ts +401 -0
- package/src/lib/liquid-actions.ts +179 -0
- package/src/lib/liquid-build-configurations.ts +410 -0
- package/src/lib/liquid-drop.ts +99 -0
- package/src/lib/liquid-engine.ts +135 -0
- package/src/lib/liquid-package.ts +108 -0
- package/src/lib/package.ts +946 -0
- package/src/lib/policies.ts +49 -0
- package/src/lib/substitutions-variables.ts +177 -0
- package/src/lib/types.ts +109 -0
- package/src/package.json +3 -0
- package/src/tsconfig.json +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-2026 Liviu Ionescu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
[](https://github.com/xpack/xpm-lib-ts/blob/mater/package.json)
|
|
2
|
+
[](https://github.com/xpack/xpm-lib-ts/blob/xpack/LICENSE)
|
|
3
|
+
[](https://www.npmjs.com/package/@xpack/xpm-lib/)
|
|
4
|
+
|
|
5
|
+
# A Node.js CommonJS/ES6 module with the Liquid substitutions code used by xpm & relatives
|
|
6
|
+
|
|
7
|
+
This project provides a **TypeScript** Node.js **CommonJS**/**ES6** module
|
|
8
|
+
with the code used to perform the Liquid substitutions when parsing
|
|
9
|
+
the xpm `package.json` file.
|
|
10
|
+
|
|
11
|
+
Note: Compatibility with legacy CommonJS is required until VS Code extensions
|
|
12
|
+
will be updated to import ES6 modules.
|
|
13
|
+
|
|
14
|
+
The project is open-source and hosted on GitHub as
|
|
15
|
+
[xpack/xpm-lib-ts](https://github.com/xpack/xpm-lib-ts.git).
|
|
16
|
+
|
|
17
|
+
## Maintainer & developer info
|
|
18
|
+
|
|
19
|
+
This page documents how to use this module in an user application.
|
|
20
|
+
For maintainer information, see the separate
|
|
21
|
+
[README-MAINTAINER](https://github.com/xpack/xpm-lib-ts/blob/master/README-MAINTAINER.md)
|
|
22
|
+
page.
|
|
23
|
+
|
|
24
|
+
## Prerequisites
|
|
25
|
+
|
|
26
|
+
A recent [Node.js](https://nodejs.org) (>=16.0.0), since the TypeScript code
|
|
27
|
+
is compiled into ECMAScript 2020 code, and the tests use ES6 modules.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
The module is available as
|
|
32
|
+
[`@xpack/xpm-lib-ts`](https://www.npmjs.com/package/@xpack/xpm-lib-ts)
|
|
33
|
+
from the public [`npmjs`](https://www.npmjs.com) repository;
|
|
34
|
+
it can be added as a dependency to any TypeScript or JavaScript
|
|
35
|
+
project with `npm install`:
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
npm install --save @xpack/xpm-libs@latest
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The module does not provide any executables, and generally there are no
|
|
42
|
+
reasons to install it globally.
|
|
43
|
+
|
|
44
|
+
## User info
|
|
45
|
+
|
|
46
|
+
This section is intended for those who want to use this module in their
|
|
47
|
+
own projects.
|
|
48
|
+
|
|
49
|
+
The `@xpack/xpm-lib` module can be imported into both TypeScript
|
|
50
|
+
and JavaScript Node.js code.
|
|
51
|
+
|
|
52
|
+
In TypeScript and ECMAScript modules, use `import`:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { XpmLiquid } from '@xpack/xpm-lib'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
In JavaScript with CommonJS, use `require()`:
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const { XpmLiquid } = require('@xpack/xpm-lib')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
To use the `XpmLiquid` class, create an instance of the engine, provide the
|
|
65
|
+
`package.json` object, possibly the name of the configuration, and
|
|
66
|
+
call `performSubstitutions()`:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const xpmLiquid = new XpmLiquid(log)
|
|
70
|
+
const xpmLiquidMap = xpmLiquid.prepareMap(packageJson, 'Debug')
|
|
71
|
+
|
|
72
|
+
const str = await xpmLiquid.performSubstitutions(
|
|
73
|
+
'{{ "build" | path_join: configuration.name | to_filename }}',
|
|
74
|
+
xpmLiquidMap)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Available variables
|
|
78
|
+
|
|
79
|
+
The entire project `package.json` is available as the `package` variable:
|
|
80
|
+
|
|
81
|
+
- `package`
|
|
82
|
+
|
|
83
|
+
All user defined properties (project and configuration) are grouped
|
|
84
|
+
below the `properties` variable:
|
|
85
|
+
|
|
86
|
+
- `properties`
|
|
87
|
+
|
|
88
|
+
If the substitution refers to a certain build configuration, the configuration
|
|
89
|
+
name and the entire configuration content are available separately below
|
|
90
|
+
the `configuration` variable. Configuration properties are added to the
|
|
91
|
+
`properties` variables, possibly overriding project properties.
|
|
92
|
+
|
|
93
|
+
- `configuration.name`
|
|
94
|
+
- `configuration.*`
|
|
95
|
+
|
|
96
|
+
Variables based on the Node.js process
|
|
97
|
+
[environment](https://nodejs.org/dist/latest-v18.x/docs/api/process.html#process_process_env):
|
|
98
|
+
|
|
99
|
+
- `env`
|
|
100
|
+
|
|
101
|
+
Variables based on the Node.js
|
|
102
|
+
[os](https://nodejs.org/dist/latest-v16.x/docs/api/os.html) definitions:
|
|
103
|
+
|
|
104
|
+
- `os.EOL`
|
|
105
|
+
- `os.arch` (like 'arm', 'arm64', 'ia32', 'x64')
|
|
106
|
+
- `os.constants`
|
|
107
|
+
- `os.cpus`
|
|
108
|
+
- `os.endianness`
|
|
109
|
+
- `os.homedir`
|
|
110
|
+
- `os.hostname`
|
|
111
|
+
- `os.platform` (like 'darwin', 'linux', 'win32')
|
|
112
|
+
- `os.release`
|
|
113
|
+
- `os.tmpdir`
|
|
114
|
+
- `os.type`
|
|
115
|
+
- `os.version` (available since Node 12)
|
|
116
|
+
|
|
117
|
+
Variables based on the Node.js
|
|
118
|
+
[path](https://nodejs.org/dist/latest-v16.x/docs/api/path.html) definitions:
|
|
119
|
+
|
|
120
|
+
- `path.delimiter` (`;` for Windows, `:` for POSIX)
|
|
121
|
+
- `path.sep` (`\` on Windows, `/` on POSIX)
|
|
122
|
+
- `path.win32.delimiter` (`;`)
|
|
123
|
+
- `path.win32.sep` (`\`)
|
|
124
|
+
- `path.posix.delimiter` (`:`)
|
|
125
|
+
- `path.posix.sep` (`/`)
|
|
126
|
+
|
|
127
|
+
Examples:
|
|
128
|
+
|
|
129
|
+
- `"buildFolderRelativePath": "build{{ path.sep }}{{ configuration.name | to_filename }}"`
|
|
130
|
+
|
|
131
|
+
### Custom filters
|
|
132
|
+
|
|
133
|
+
Filters based on Node.js
|
|
134
|
+
[path](https://nodejs.org/dist/latest-v16.x/docs/api/path.html) functions:
|
|
135
|
+
|
|
136
|
+
- `path_basename`
|
|
137
|
+
- `path_dirname`
|
|
138
|
+
- `path_normalize`
|
|
139
|
+
- `path_join`
|
|
140
|
+
- `path_relative`
|
|
141
|
+
- `path_posix_basename`
|
|
142
|
+
- `path_posix_dirname`
|
|
143
|
+
- `path_posix_normalize`
|
|
144
|
+
- `path_posix_join`
|
|
145
|
+
- `path_posix_relative`
|
|
146
|
+
- `path_win32_basename`
|
|
147
|
+
- `path_win32_dirname`
|
|
148
|
+
- `path_win32_normalize`
|
|
149
|
+
- `path_win32_join`
|
|
150
|
+
- `path_win32_relative`
|
|
151
|
+
|
|
152
|
+
Filters based on Node.js
|
|
153
|
+
[utils](https://nodejs.org/dist/latest-v16.x/docs/api/util.html) functions:
|
|
154
|
+
|
|
155
|
+
- `util_format`
|
|
156
|
+
|
|
157
|
+
Custom filter to convert generic names to names accepted
|
|
158
|
+
as file names (letters, digits, dash):
|
|
159
|
+
|
|
160
|
+
- `to_filename`
|
|
161
|
+
- `to_posix_filename`
|
|
162
|
+
- `to_win32_filename`
|
|
163
|
+
|
|
164
|
+
Examples:
|
|
165
|
+
|
|
166
|
+
- `"buildFolderRelativePath": "{{ "build" | path_join: configuration.name | to_filename | downcase }"`
|
|
167
|
+
|
|
168
|
+
### Lenient if's
|
|
169
|
+
|
|
170
|
+
The undefined variables in tests do not trigger `undefined variable` messages
|
|
171
|
+
and allow to use defaults, like:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
{{ env.OPTIMIZATION | default: '-O2' }}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Reference
|
|
178
|
+
|
|
179
|
+
For more details on the available class definitions, including all methods,
|
|
180
|
+
accessors, properties, etc,
|
|
181
|
+
please see the TypeDoc
|
|
182
|
+
[reference pages](https://xpack.github.io/xpm-lib-ts/).
|
|
183
|
+
|
|
184
|
+
## Known problems
|
|
185
|
+
|
|
186
|
+
- none
|
|
187
|
+
|
|
188
|
+
## Status
|
|
189
|
+
|
|
190
|
+
The `@xpack/xpm-lib-ts` module is fully functional and stable.
|
|
191
|
+
|
|
192
|
+
The main clients for this module is the `xpm` CLI application and the
|
|
193
|
+
[VS Code xPack C/C++ Managed Build](https://github.com/xpack/vscode-xpack-extension-ts/)
|
|
194
|
+
extension.
|
|
195
|
+
|
|
196
|
+
## Tests
|
|
197
|
+
|
|
198
|
+
The module is tested
|
|
199
|
+
with 100% coverage and CI tested on every push via GitHub
|
|
200
|
+
[Actions](https://github.com/xpack/xpm-lib-ts/actions).
|
|
201
|
+
|
|
202
|
+
## Compatibility notices
|
|
203
|
+
|
|
204
|
+
According to [semver](https://semver.org) rules:
|
|
205
|
+
|
|
206
|
+
> Major version X (X.y.z | X > 0) MUST be incremented if any
|
|
207
|
+
backwards incompatible changes are introduced to the public API.
|
|
208
|
+
|
|
209
|
+
### v3.0.0
|
|
210
|
+
|
|
211
|
+
The API was greatly extended to use XpmPackage & XpmLiquid*.
|
|
212
|
+
The project was renamed xpm-lib and updated to ESM only.
|
|
213
|
+
|
|
214
|
+
### v2.0.0
|
|
215
|
+
|
|
216
|
+
The project was updated to dual ESM & CJS.
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
The original content is released under the
|
|
221
|
+
[MIT License](https://opensource.org/license/mit),
|
|
222
|
+
with all rights reserved to
|
|
223
|
+
[Liviu Ionescu](https://github.com/ilg-ul).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './lib/functions/chmod-recursive.js';
|
|
2
|
+
export * from './lib/functions/perform-substitutions.js';
|
|
3
|
+
export * from './lib/functions/utils.js';
|
|
4
|
+
export * from './lib/errors.js';
|
|
5
|
+
export * from './lib/init-template-base.js';
|
|
6
|
+
export * from './lib/liquid-actions.js';
|
|
7
|
+
export * from './lib/liquid-build-configurations.js';
|
|
8
|
+
export * from './lib/liquid-drop.js';
|
|
9
|
+
export * from './lib/liquid-engine.js';
|
|
10
|
+
export * from './lib/liquid-package.js';
|
|
11
|
+
export * from './lib/package.js';
|
|
12
|
+
export * from './lib/policies.js';
|
|
13
|
+
export * from './lib/substitutions-variables.js';
|
|
14
|
+
export * from './lib/types.js';
|
|
15
|
+
export * from 'liquidjs';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,cAAc,oCAAoC,CAAA;AAClD,cAAc,0CAA0C,CAAA;AACxD,cAAc,0BAA0B,CAAA;AAExC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,sCAAsC,CAAA;AACpD,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kCAAkC,CAAA;AAChD,cAAc,gBAAgB,CAAA;AAE9B,cAAc,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the xPack project (http://xpack.github.io).
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* If a copy of the license was not distributed with this file, it can
|
|
9
|
+
* be obtained from https://opensource.org/license/mit.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
// Re-export all library definitions.
|
|
14
|
+
export * from './lib/functions/chmod-recursive.js';
|
|
15
|
+
export * from './lib/functions/perform-substitutions.js';
|
|
16
|
+
export * from './lib/functions/utils.js';
|
|
17
|
+
export * from './lib/errors.js';
|
|
18
|
+
export * from './lib/init-template-base.js';
|
|
19
|
+
export * from './lib/liquid-actions.js';
|
|
20
|
+
export * from './lib/liquid-build-configurations.js';
|
|
21
|
+
export * from './lib/liquid-drop.js';
|
|
22
|
+
export * from './lib/liquid-engine.js';
|
|
23
|
+
export * from './lib/liquid-package.js';
|
|
24
|
+
export * from './lib/package.js';
|
|
25
|
+
export * from './lib/policies.js';
|
|
26
|
+
export * from './lib/substitutions-variables.js';
|
|
27
|
+
export * from './lib/types.js';
|
|
28
|
+
export * from 'liquidjs';
|
|
29
|
+
// ----------------------------------------------------------------------------
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,qCAAqC;AACrC,cAAc,oCAAoC,CAAA;AAClD,cAAc,0CAA0C,CAAA;AACxD,cAAc,0BAA0B,CAAA;AAExC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,yBAAyB,CAAA;AACvC,cAAc,sCAAsC,CAAA;AACpD,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,kCAAkC,CAAA;AAChD,cAAc,gBAAgB,CAAA;AAE9B,cAAc,UAAU,CAAA;AAExB,+EAA+E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chmod-recursive.d.ts","sourceRoot":"","sources":["../../src/lib/chmod-recursive.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAItC,wBAAsB,cAAc,CAAC,EACnC,SAAS,EACT,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoEhB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the xPack project (http://xpack.github.io).
|
|
3
|
+
* Copyright (c) 2017-2025 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* If a copy of the license was not distributed with this file, it can
|
|
9
|
+
* be obtained from https://opensource.org/license/mit.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
// https://nodejs.org/docs/latest/api/
|
|
14
|
+
import assert from 'node:assert';
|
|
15
|
+
import * as fs from 'node:fs/promises';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
export async function chmodRecursive({ inputPath, readOnly, log, }) {
|
|
19
|
+
assert(inputPath, 'mandatory inputPath');
|
|
20
|
+
assert(log, 'mandatory log');
|
|
21
|
+
const stat = await fs.lstat(inputPath);
|
|
22
|
+
// log.trace(util.inspect(stat))
|
|
23
|
+
if (stat.isSymbolicLink()) {
|
|
24
|
+
// Since it is not possible to change the modes of links (lchmod
|
|
25
|
+
// was deprecated and worked on macOS anyway), don't bother
|
|
26
|
+
// with them.
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// The order is important, process the folder before
|
|
30
|
+
// changing it to RO.
|
|
31
|
+
if (readOnly && stat.isDirectory()) {
|
|
32
|
+
log.trace(inputPath);
|
|
33
|
+
const dirents = await fs.readdir(inputPath, {
|
|
34
|
+
withFileTypes: true,
|
|
35
|
+
});
|
|
36
|
+
for (const dirent of dirents) {
|
|
37
|
+
await chmodRecursive({
|
|
38
|
+
inputPath: path.resolve(inputPath, dirent.name),
|
|
39
|
+
readOnly,
|
|
40
|
+
log,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const mode = stat.mode;
|
|
45
|
+
// For RO, remove all W bits, for RW add only user.
|
|
46
|
+
const newMode = readOnly
|
|
47
|
+
? mode &
|
|
48
|
+
~(fs.constants.S_IWUSR | fs.constants.S_IWGRP | fs.constants.S_IWOTH)
|
|
49
|
+
: mode | fs.constants.S_IWUSR;
|
|
50
|
+
// log.trace(
|
|
51
|
+
// `set ${inputPath} from ${mode.toString(8)} to ${newMode.toString(8)}`)
|
|
52
|
+
await fs.chmod(inputPath, newMode);
|
|
53
|
+
const actualStat = await fs.stat(inputPath);
|
|
54
|
+
// log.trace(`actual ${inputPath} is ${actualStat.mode.toString(8)}`)
|
|
55
|
+
if (readOnly) {
|
|
56
|
+
if ((actualStat.mode & fs.constants.S_IWUSR) !== 0) {
|
|
57
|
+
log.warn(`${inputPath} not set to RO`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if ((actualStat.mode & fs.constants.S_IWUSR) === 0) {
|
|
62
|
+
log.warn(`${inputPath} not set to RW`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// If RW, process the folder after changing it to RW.
|
|
66
|
+
if (!readOnly && stat.isDirectory()) {
|
|
67
|
+
log.trace(inputPath);
|
|
68
|
+
const dirents = await fs.readdir(inputPath, {
|
|
69
|
+
withFileTypes: true,
|
|
70
|
+
});
|
|
71
|
+
for (const dirent of dirents) {
|
|
72
|
+
await chmodRecursive({
|
|
73
|
+
inputPath: path.resolve(inputPath, dirent.name),
|
|
74
|
+
readOnly,
|
|
75
|
+
log,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ----------------------------------------------------------------------------
|
|
81
|
+
//# sourceMappingURL=chmod-recursive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,+EAA+E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class XpmError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class XpmPrerequisitesError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export declare class XpmInputError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export declare class XpmSyntaxError extends Error {
|
|
8
|
+
}
|
|
9
|
+
export declare class XpmOutputError extends Error {
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAgBA,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,qBAAa,qBAAsB,SAAQ,KAAK;CAAG;AAEnD,qBAAa,aAAc,SAAQ,KAAK;CAAG;AAE3C,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C,qBAAa,cAAe,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the xPack project (http://xpack.github.io).
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* If a copy of the license was not distributed with this file, it can
|
|
9
|
+
* be obtained from https://opensource.org/license/mit.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
// Application errors
|
|
14
|
+
export class XpmError extends Error {
|
|
15
|
+
}
|
|
16
|
+
export class XpmPrerequisitesError extends Error {
|
|
17
|
+
}
|
|
18
|
+
export class XpmInputError extends Error {
|
|
19
|
+
}
|
|
20
|
+
export class XpmSyntaxError extends Error {
|
|
21
|
+
}
|
|
22
|
+
export class XpmOutputError extends Error {
|
|
23
|
+
}
|
|
24
|
+
// Other errors: Child.
|
|
25
|
+
// ----------------------------------------------------------------------------
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,qBAAqB;AACrB,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,MAAM,OAAO,qBAAsB,SAAQ,KAAK;CAAG;AAEnD,MAAM,OAAO,aAAc,SAAQ,KAAK;CAAG;AAE3C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,MAAM,OAAO,cAAe,SAAQ,KAAK;CAAG;AAE5C,wBAAwB;AAExB,+EAA+E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chmod-recursive.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/chmod-recursive.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAItC,wBAAsB,cAAc,CAAC,EACnC,SAAS,EACT,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAoEhB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the xPack project (http://xpack.github.io).
|
|
3
|
+
* Copyright (c) 2017-2026 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* If a copy of the license was not distributed with this file, it can
|
|
9
|
+
* be obtained from https://opensource.org/license/mit.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
// https://nodejs.org/docs/latest/api/
|
|
14
|
+
import assert from 'node:assert';
|
|
15
|
+
import * as fs from 'node:fs/promises';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
// ----------------------------------------------------------------------------
|
|
18
|
+
export async function chmodRecursive({ inputPath, readOnly, log, }) {
|
|
19
|
+
assert(inputPath, 'mandatory inputPath');
|
|
20
|
+
assert(log, 'mandatory log');
|
|
21
|
+
const stat = await fs.lstat(inputPath);
|
|
22
|
+
// log.trace(util.inspect(stat))
|
|
23
|
+
if (stat.isSymbolicLink()) {
|
|
24
|
+
// Since it is not possible to change the modes of links (lchmod
|
|
25
|
+
// was deprecated and worked on macOS anyway), don't bother
|
|
26
|
+
// with them.
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// The order is important, process the folder before
|
|
30
|
+
// changing it to RO.
|
|
31
|
+
if (readOnly && stat.isDirectory()) {
|
|
32
|
+
log.trace(inputPath);
|
|
33
|
+
const dirents = await fs.readdir(inputPath, {
|
|
34
|
+
withFileTypes: true,
|
|
35
|
+
});
|
|
36
|
+
for (const dirent of dirents) {
|
|
37
|
+
await chmodRecursive({
|
|
38
|
+
inputPath: path.resolve(inputPath, dirent.name),
|
|
39
|
+
readOnly,
|
|
40
|
+
log,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const mode = stat.mode;
|
|
45
|
+
// For RO, remove all W bits, for RW add only user.
|
|
46
|
+
const newMode = readOnly
|
|
47
|
+
? mode &
|
|
48
|
+
~(fs.constants.S_IWUSR | fs.constants.S_IWGRP | fs.constants.S_IWOTH)
|
|
49
|
+
: mode | fs.constants.S_IWUSR;
|
|
50
|
+
// log.trace(
|
|
51
|
+
// `set ${inputPath} from ${mode.toString(8)} to ${newMode.toString(8)}`)
|
|
52
|
+
await fs.chmod(inputPath, newMode);
|
|
53
|
+
const actualStat = await fs.stat(inputPath);
|
|
54
|
+
// log.trace(`actual ${inputPath} is ${actualStat.mode.toString(8)}`)
|
|
55
|
+
if (readOnly) {
|
|
56
|
+
if ((actualStat.mode & fs.constants.S_IWUSR) !== 0) {
|
|
57
|
+
log.warn(`${inputPath} not set to RO`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if ((actualStat.mode & fs.constants.S_IWUSR) === 0) {
|
|
62
|
+
log.warn(`${inputPath} not set to RW`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// If RW, process the folder after changing it to RW.
|
|
66
|
+
if (!readOnly && stat.isDirectory()) {
|
|
67
|
+
log.trace(inputPath);
|
|
68
|
+
const dirents = await fs.readdir(inputPath, {
|
|
69
|
+
withFileTypes: true,
|
|
70
|
+
});
|
|
71
|
+
for (const dirent of dirents) {
|
|
72
|
+
await chmodRecursive({
|
|
73
|
+
inputPath: path.resolve(inputPath, dirent.name),
|
|
74
|
+
readOnly,
|
|
75
|
+
log,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ----------------------------------------------------------------------------
|
|
81
|
+
//# sourceMappingURL=chmod-recursive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chmod-recursive.js","sourceRoot":"","sources":["../../../src/lib/functions/chmod-recursive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,sCAAsC;AACtC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,IAAI,MAAM,WAAW,CAAA;AAI5B,+EAA+E;AAE/E,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,S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M,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC3C,qEAAqE;IAErE,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnD,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,gBAAgB,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACnD,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,gBAAgB,CAAC,CAAA;QACxC,CAAC;IACH,CAAC;IAED,qDAAqD;IACrD,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QACpC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QACpB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE;YAC1C,aAAa,EAAE,IAAI;SACpB,CAAC,CAAA;QACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,cAAc,CAAC;gBACnB,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC;gBAC/C,QAAQ;gBACR,GAAG;aACJ,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,+EAA+E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Logger } from '@xpack/logger';
|
|
2
|
+
import { XpmLiquidEngine } from '../liquid-engine.js';
|
|
3
|
+
import { XpmLiquidSubstitutionsVariables } from '../substitutions-variables.js';
|
|
4
|
+
/**
|
|
5
|
+
* Perform substitution on the input string.
|
|
6
|
+
* Repeat until no more Liquid variables or tags are identified.
|
|
7
|
+
*
|
|
8
|
+
* @param input - The input string, possibly with substitutions.
|
|
9
|
+
* @param map - The substitution map.
|
|
10
|
+
* @returns The substituted string.
|
|
11
|
+
*
|
|
12
|
+
* @throws Liquid exceptions
|
|
13
|
+
*/
|
|
14
|
+
export declare function performSubstitutions({ log, engine, input, substitutionsVariables, }: {
|
|
15
|
+
log: Logger;
|
|
16
|
+
engine: XpmLiquidEngine;
|
|
17
|
+
input: string;
|
|
18
|
+
substitutionsVariables: XpmLiquidSubstitutionsVariables;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
//# sourceMappingURL=perform-substitutions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perform-substitutions.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/perform-substitutions.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAA;AAG/E;;;;;;;;;GASG;AAEH,wBAAsB,oBAAoB,CAAC,EACzC,GAAG,EACH,MAAM,EACN,KAAK,EACL,sBAAsB,GACvB,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,eAAe,CAAA;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,sBAAsB,EAAE,+BAA+B,CAAA;CACxD,GAAG,OAAO,CAAC,MAAM,CAAC,CAkElB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of the xPack project (http://xpack.github.io).
|
|
3
|
+
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
* for any purpose is hereby granted, under the terms of the MIT license.
|
|
7
|
+
*
|
|
8
|
+
* If a copy of the license was not distributed with this file, it can
|
|
9
|
+
* be obtained from https://opensource.org/license/mit.
|
|
10
|
+
*/
|
|
11
|
+
/* eslint max-len: [ "error", 80, { "ignoreUrls": true } ] */
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
import assert from 'node:assert';
|
|
14
|
+
import { Context } from 'liquidjs';
|
|
15
|
+
import { XpmLiquidPropertiesDrop } from '../liquid-drop.js';
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
/**
|
|
18
|
+
* Perform substitution on the input string.
|
|
19
|
+
* Repeat until no more Liquid variables or tags are identified.
|
|
20
|
+
*
|
|
21
|
+
* @param input - The input string, possibly with substitutions.
|
|
22
|
+
* @param map - The substitution map.
|
|
23
|
+
* @returns The substituted string.
|
|
24
|
+
*
|
|
25
|
+
* @throws Liquid exceptions
|
|
26
|
+
*/
|
|
27
|
+
export async function performSubstitutions({ log, engine, input, substitutionsVariables, }) {
|
|
28
|
+
assert(substitutionsVariables);
|
|
29
|
+
if (input.trim() === '') {
|
|
30
|
+
// Spare it the trouble for empty strings.
|
|
31
|
+
return input;
|
|
32
|
+
}
|
|
33
|
+
let context;
|
|
34
|
+
// Wrap properties into a liquid drop (a mechanism to process
|
|
35
|
+
// substitutions immediately).
|
|
36
|
+
if (Object.keys(substitutionsVariables.properties).length > 0) {
|
|
37
|
+
context = new Context({
|
|
38
|
+
...substitutionsVariables,
|
|
39
|
+
properties: new XpmLiquidPropertiesDrop({
|
|
40
|
+
log,
|
|
41
|
+
engine,
|
|
42
|
+
properties: substitutionsVariables.properties,
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
context = new Context(substitutionsVariables);
|
|
48
|
+
}
|
|
49
|
+
log.trace(`performSubstitutions('${input}')`);
|
|
50
|
+
let current = input;
|
|
51
|
+
let substituted = current;
|
|
52
|
+
let count = 0;
|
|
53
|
+
// Iterate until all substitutions are done.
|
|
54
|
+
while (current.includes('{{') || current.includes('{%')) {
|
|
55
|
+
++count;
|
|
56
|
+
// May throw.
|
|
57
|
+
try {
|
|
58
|
+
substituted = (await engine.parseAndRender(current, context));
|
|
59
|
+
/* c8 ignore start */ /* istanbul ignore next */
|
|
60
|
+
if (substituted === current) {
|
|
61
|
+
// If nothing changed, we're done.
|
|
62
|
+
// This test is just a safety net, normally should not get there.
|
|
63
|
+
log.warn(`performSubstitutions() ${String(count)} => |`, substituted, '| did not change');
|
|
64
|
+
break;
|
|
65
|
+
} /* c8 ignore stop */
|
|
66
|
+
}
|
|
67
|
+
catch (ex) {
|
|
68
|
+
if (ex instanceof Error) {
|
|
69
|
+
// log.error(ex)
|
|
70
|
+
log.error(ex.message);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
log.error(new Error(String(ex)));
|
|
74
|
+
}
|
|
75
|
+
// Return the current (unsubstituted) value.
|
|
76
|
+
substituted = current;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
log.trace(`performSubstitutions() ${String(count)} => |`, substituted, '|');
|
|
80
|
+
current = substituted;
|
|
81
|
+
}
|
|
82
|
+
return substituted;
|
|
83
|
+
}
|
|
84
|
+
// ----------------------------------------------------------------------------
|
|
85
|
+
//# sourceMappingURL=perform-substitutions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perform-substitutions.js","sourceRoot":"","sources":["../../../src/lib/functions/perform-substitutions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,6DAA6D;AAE7D,+EAA+E;AAE/E,OAAO,MAAM,MAAM,aAAa,CAAA;AAEhC,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAKlC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAG3D,+EAA+E;AAC/E;;;;;;;;;GASG;AAEH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,EACzC,GAAG,EACH,MAAM,EACN,KAAK,EACL,sBAAsB,GAMvB;IACC,MAAM,CAAC,sBAAsB,CAAC,CAAA;IAE9B,IAAI,KAAK,CAAC,IAAI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