@pi-r/android 0.12.2 → 0.12.4

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.
@@ -5,7 +5,7 @@ const fs = require('node:fs');
5
5
  const Document = require('@e-mc/document');
6
6
  const { escapePattern, isArray, isString } = require('@e-mc/types');
7
7
  const { getIndent, getNewline, spliceString, trimQuote, wrapQuote } = require('@e-mc/document/util');
8
- const REGEXP_SEMVER = /^((\s*,\s*)?[([\]]((\s*,\s*)?\d+\.\d+(\s*,\s*)?)+[)[\]])+$/;
8
+ const REGEXP_SEMVER = /^(?:(?:\s*,\s*)?(?:[([\]](?:(?:\s*,\s*)?\d+\.\d+(?:\s*,\s*)?)+[)[\]]|!!\d+\.\d+\.\d+|\d+\.\d+\.\d+!!))+$/;
9
9
  const REGEXP_DEPENDENCIES = /dependencies\s+\{((?:{[^{]*{|{[^}]*}|}[^}]*}|\\}*?|[^{}+])+)\}/;
10
10
  const REGEXP_DEPENDENCY = /([ \t]*)([A-Za-z_$][\w$]*)(?:\s*\(?\s*(?:module\(?\s*)?["']([^"']+)["']\s*\)?|\s+((?:\s*(?:group|name|version)\s*:\s*(?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*,?){3}))?/g;
11
11
  const REGEXP_DEPENDENCY_KOTLIN = /([ \t]*)([A-Za-z_$][\w$]*)\((?:\s*(?:(?:module\(\s*)?"([^"]+)"|((?:\s*(?:group|name|version)\s*=\s*"(?:[^"]|(?<=\\)")+"\s*,?){3}))\s*\))?/g;
@@ -13,7 +13,7 @@ const REGEXP_LIBRARY = /([ \t]*)implementation\s+(?:(project|files)\(\s*("(?:[^"
13
13
  const REGEXP_LIBRARY_KOTLIN = /([ \t]*)implementation\(\s*(?:(project|files)\(\s*"(.+)"\s*\)|(fileTree)\(\s*mapOf\(((?:\s*"(?:dir|include)"\s+to\s+(?:"(?:[^"]|(?<=\\)")+"|listOf\([^)]+\))\s*,?){2})\)\s*\))\s*\)[ \t\r]*\n/g;
14
14
  const REGEXP_PLATFORM = /([ \t]*)implementation\s+platform\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*\)[ \t\r]*\n/g;
15
15
  const REGEXP_PLATFORM_KOTLIN = /([ \t]*)implementation\(\s*platform\(\s*"(.+)"\s*\)\s*\)[ \t\r]*\n/g;
16
- const REGEXP_VERSIONS = /(\S+)\s*=\s*(?:"([^"]+)"|'([^']+)'|(\{(?:\s*(?:require|strictly|prefer|reject(?:All)?)\s*=\s*(?:"[^"]+"|'[^']+')\s*,?)+\s*\}))/g;
16
+ const REGEXP_VERSIONS = /(\S+)\s*=\s*(?:"([^"]+)"|'([^']+)')/g;
17
17
  const REGEXP_VERSIONS_LIB = /(\S+)\s*=\s*(?:\{\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)'|(\{[^}]+\}))\s*,\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)'|(\{[^}]+\}))(?:\s*,\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)')|(\{[^}]+\}))?\s*\}|(?:"([^:]+:[^"]+)"|'([^:]+:[^']+)'))/gd;
18
18
  function isUpgrade(version, pending) {
19
19
  if (isSemVer(pending)) {
@@ -137,7 +137,7 @@ function finalize(instance) {
137
137
  const hasScope = (value) => isArray(dependencyScopes) && dependencyScopes.includes(value) || dependencyScopes === value;
138
138
  const snapshot = dependencyScopes === 1 || hasScope('snapshot');
139
139
  const constraints = hasScope('constraints');
140
- const checkVersion = (item, version, value) => !value && version.startsWith('{') && version.endsWith('}') ? false : snapshot || constraints && !item[2] || (version.length > 0 && !version.startsWith('$') || !kotlin && !!value?.includes("'")) && isUpgrade(version, item[2]);
140
+ const checkVersion = (item, version, value) => snapshot || constraints && !item[2] || (version.length > 0 && !version.startsWith('$') || !kotlin && !!value?.includes("'")) && isUpgrade(version, item[2]);
141
141
  const getData = () => mavenData ||= instance.findData('google-maven' + (snapshot ? '-snapshot' : '') + '.json', 'json');
142
142
  const items = dependencies.map(item => {
143
143
  let [groupId, artifactId, version, type] = item.split(':');
@@ -264,7 +264,7 @@ function finalize(instance) {
264
264
  const versions = {};
265
265
  let config = template.source, catalog;
266
266
  for (const ref of config.matchAll(REGEXP_VERSIONS)) {
267
- versions[ref[1]] = (ref[2] || ref[3] || ref[4]).trim();
267
+ versions[ref[1]] = (ref[2] || ref[3]).trim();
268
268
  }
269
269
  while (catalog = REGEXP_VERSIONS_LIB.exec(config)) {
270
270
  const lib = {};
@@ -301,10 +301,13 @@ function finalize(instance) {
301
301
  const version = ref ? versions[ref] : lib.version;
302
302
  if (version && checkVersion(item, version)) {
303
303
  if (ref) {
304
- const target = new RegExp(`\\s${escapePattern(ref)}\\s*=\\s*(?:"([^"]+)"|'([^']+)')`, 'd').exec(config);
305
- if (target?.indices) {
306
- const [start, end] = target.indices[1] || target.indices[2];
307
- config = spliceString(config, start, end, versions[ref] = item[2], REGEXP_VERSIONS_LIB);
304
+ if (versions[ref] !== item[2]) {
305
+ const target = new RegExp(`\\s${escapePattern(ref)}\\s*=\\s*(?:"([^"]+)"|'([^']+)')`, 'd').exec(config);
306
+ const indices = target?.indices;
307
+ if (indices) {
308
+ const [start, end] = indices[1] || indices[2];
309
+ config = spliceString(config, start, end, versions[ref] = item[2], REGEXP_VERSIONS_LIB);
310
+ }
308
311
  }
309
312
  }
310
313
  else if (lib.version_indices) {
@@ -363,7 +366,7 @@ function finalize(instance) {
363
366
  config = writeOutput(lib, config, output);
364
367
  }
365
368
  else {
366
- config += output;
369
+ config += (config.endsWith(newLine) ? '' : newLine) + output;
367
370
  }
368
371
  if (outputVer) {
369
372
  outputVer = '[versions]' + newLine + outputVer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/android",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "description": "Android document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,8 +17,8 @@
17
17
  "license": "MIT",
18
18
  "homepage": "https://github.com/anpham6/pi-r#readme",
19
19
  "dependencies": {
20
- "@e-mc/document": "^0.14.3",
21
- "@e-mc/types": "^0.14.3",
20
+ "@e-mc/document": "^0.14.5",
21
+ "@e-mc/types": "^0.14.5",
22
22
  "dom-serializer": "^2.0.0",
23
23
  "domhandler": "^5.0.3",
24
24
  "domutils": "^3.2.2",