react-native-nano-icons 1.0.1 → 1.1.0-beta.1

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.
Files changed (117) hide show
  1. package/README.md +137 -21
  2. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +7 -0
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +6 -1
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +4 -2
  8. package/ios/NanoIconView.mm +12 -0
  9. package/ios/NanoIconsFontLoader.mm +5 -0
  10. package/lib/commonjs/cli/build.d.ts +26 -0
  11. package/lib/commonjs/cli/build.js +174 -64
  12. package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
  13. package/lib/commonjs/cli/buildSymbols.js +103 -42
  14. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  15. package/lib/commonjs/cli/expoConfig.js +22 -7
  16. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  17. package/lib/commonjs/cli/fingerprint.js +36 -0
  18. package/lib/commonjs/cli/index.d.ts +2 -2
  19. package/lib/commonjs/cli/index.js +3 -1
  20. package/lib/commonjs/cli/link.d.ts +4 -0
  21. package/lib/commonjs/cli/link.js +25 -0
  22. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  23. package/lib/commonjs/cli/sameOutputs.js +45 -0
  24. package/lib/commonjs/index.node.js +1 -1
  25. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  26. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  27. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  28. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  29. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  30. package/lib/commonjs/plugin/src/frozen.js +18 -0
  31. package/lib/commonjs/plugin/src/index.js +3 -3
  32. package/lib/commonjs/plugin/src/types.d.ts +10 -0
  33. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  34. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  35. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  36. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  37. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  38. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  39. package/lib/commonjs/scripts/cli.js +31 -2
  40. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  41. package/lib/commonjs/src/core/flatten/element.js +2 -1
  42. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  43. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  44. package/lib/commonjs/src/core/font/compile.js +2 -8
  45. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  46. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  47. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  48. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  49. package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
  50. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  51. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  52. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  53. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  54. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  55. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  56. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  57. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  58. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  59. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  60. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  61. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  62. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  63. package/lib/module/createNanoIconsSet.js +0 -1
  64. package/lib/module/createNanoIconsSet.native.js +22 -18
  65. package/lib/module/createNanoIconsSet.shared.js +32 -18
  66. package/lib/module/createNanoIconsSet.web.js +103 -61
  67. package/lib/module/devServerFont.js +1 -1
  68. package/lib/module/devServerFont.web.js +3 -5
  69. package/lib/module/fontIntegrity.js +20 -38
  70. package/lib/module/fontIntegrity.web.js +48 -0
  71. package/lib/module/fontIntegrityStore.js +65 -0
  72. package/lib/module/index.js +1 -1
  73. package/lib/module/index.node.js +1 -1
  74. package/lib/module/index.web.js +4 -0
  75. package/lib/module/loadDynamicFont.js +3 -15
  76. package/lib/module/specs/NanoIconViewNativeComponent.ts +2 -1
  77. package/lib/module/utils/fingerPrint.js +3 -2
  78. package/lib/module/utils/fontIdentity.js +2 -2
  79. package/lib/module/utils/fontScale.js +10 -2
  80. package/lib/module/utils/glyphRuntime.js +13 -0
  81. package/lib/module/utils/iconAccessibility.js +26 -0
  82. package/lib/module/utils/iconPropsEqual.js +27 -0
  83. package/lib/module/utils/webCss.js +26 -0
  84. package/lib/module/utils/webStyle.js +86 -0
  85. package/lib/module/webFont.js +33 -0
  86. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  87. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  88. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  89. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  90. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  91. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  92. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  93. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  94. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  95. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  96. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  97. package/lib/typescript/src/index.d.ts +2 -1
  98. package/lib/typescript/src/index.web.d.ts +5 -0
  99. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  100. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +2 -1
  101. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  102. package/lib/typescript/src/types.d.ts +37 -9
  103. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  104. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  105. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  106. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  107. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  108. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  109. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  110. package/lib/typescript/src/webFont.d.ts +6 -0
  111. package/package.json +19 -3
  112. package/src/const/codegenPrimitives.ts +3 -3
  113. package/src/specs/NanoIconViewNativeComponent.ts +2 -1
  114. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  115. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  116. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  117. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -4,10 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.IconSetBuildError = void 0;
7
+ exports.fingerprintIconSets = fingerprintIconSets;
8
+ exports.checkAllFonts = checkAllFonts;
7
9
  exports.buildAllFonts = buildAllFonts;
8
10
  const path_1 = __importDefault(require("path"));
9
11
  const fs_1 = __importDefault(require("fs"));
12
+ const util_1 = require("util");
10
13
  const index_1 = require("../src/core/pipeline/index");
14
+ const quadratic_1 = require("../src/core/font/quadratic");
15
+ const link_1 = require("./link");
16
+ const sameOutputs_1 = require("./sameOutputs");
11
17
  const fingerPrint_1 = require("../src/utils/fingerPrint");
12
18
  const packageVersion_1 = require("../src/utils/packageVersion");
13
19
  class IconSetBuildError extends Error {
@@ -28,32 +34,171 @@ function webOutputFor(configured, withWeb) {
28
34
  return 'required';
29
35
  return 'ignored';
30
36
  }
31
- function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger) {
32
- const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
33
- const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
34
- const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
35
- if (!fs_1.default.existsSync(outputDir) ||
36
- !fs_1.default.existsSync(ttfPath) ||
37
- !fs_1.default.existsSync(glyphmapPath) ||
38
- (webOutput === 'required' && !fs_1.default.existsSync(woff2Path))) {
39
- return undefined;
37
+ const STALE_REASON = {
38
+ missing: (file) => `${file} is missing`,
39
+ invalidJson: (file) => `${file} is not valid JSON`,
40
+ incomplete: (file) => `${file} is incomplete`,
41
+ inputsChanged: 'its SVGs, options or installed versions changed',
42
+ linkingChanged: (linking) => `its linking changed to "${linking}"`,
43
+ webOutputChanged: (enabled) => `web output was turned ${enabled ? 'on' : 'off'}`,
44
+ };
45
+ function currentOutput(set, logger) {
46
+ const { fontFamily, ttfPath, glyphmapPath, woff2Path, webOutput } = set;
47
+ const missing = [
48
+ ttfPath,
49
+ glyphmapPath,
50
+ ...(webOutput === 'required' ? [woff2Path] : []),
51
+ ].find((file) => !fs_1.default.existsSync(file));
52
+ if (missing) {
53
+ return { staleBecause: STALE_REASON.missing(path_1.default.basename(missing)) };
54
+ }
55
+ let glyphmap;
56
+ try {
57
+ glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
58
+ }
59
+ catch {
60
+ return {
61
+ staleBecause: STALE_REASON.invalidJson(path_1.default.basename(glyphmapPath)),
62
+ };
40
63
  }
41
- const glyphmap = JSON.parse(fs_1.default.readFileSync(glyphmapPath, 'utf8'));
42
64
  const storedHash = glyphmap?.m?.h;
43
65
  const storedFamily = glyphmap?.m?.f;
44
66
  const storedLinking = glyphmap?.m?.l === 'd' ? 'dynamic' : 'static';
45
67
  const storedWeb = glyphmap?.m?.w === true;
46
- const webCurrent = webOutput === 'ignored' || storedWeb === (webOutput === 'required');
47
- if (storedHash &&
48
- storedFamily &&
49
- storedHash === inputHash &&
50
- storedLinking === linking &&
51
- webCurrent) {
52
- const iconCount = Object.keys(glyphmap?.i ?? {}).length;
53
- logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
54
- return storedFamily;
68
+ if (!storedHash || !storedFamily) {
69
+ return {
70
+ staleBecause: STALE_REASON.incomplete(path_1.default.basename(glyphmapPath)),
71
+ };
72
+ }
73
+ if (storedHash !== set.inputHash) {
74
+ return { staleBecause: STALE_REASON.inputsChanged };
75
+ }
76
+ if (storedLinking !== set.linking) {
77
+ return { staleBecause: STALE_REASON.linkingChanged(set.linking) };
78
+ }
79
+ if (webOutput !== 'ignored' && storedWeb !== (webOutput === 'required')) {
80
+ return { staleBecause: STALE_REASON.webOutputChanged(!storedWeb) };
81
+ }
82
+ const iconCount = Object.keys(glyphmap?.i ?? {}).length;
83
+ logger?.succeed(`${fontFamily}.ttf is up to date [${iconCount} icon${iconCount === 1 ? '' : 's'}]`);
84
+ return { family: storedFamily };
85
+ }
86
+ function resolveIconSet(set, projectRoot, withWeb, versions) {
87
+ const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
88
+ const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
89
+ const linking = set.linking ?? 'static';
90
+ const web = (set.web ?? false) && withWeb;
91
+ const webOutput = webOutputFor(set.web ?? false, withWeb);
92
+ if (!fs_1.default.existsSync(inputDir)) {
93
+ throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
94
+ }
95
+ const upm = set.upm ?? DEFAULT_UPM;
96
+ const safeZone = set.safeZone ?? Math.round(upm * DEFAULT_SAFE_ZONE_RATIO);
97
+ if (safeZone > upm) {
98
+ throw new Error(`[react-native-nano-icons] safeZone (${safeZone}) of "${fontFamily}" must not exceed upm (${upm}).`);
99
+ }
100
+ const curveTolerance = set.curveTolerance ?? quadratic_1.QUADRATIC_ERROR_BOUND_EM;
101
+ if (!Number.isFinite(curveTolerance) || curveTolerance <= 0) {
102
+ throw new Error(`[react-native-nano-icons] curveTolerance (${(0, util_1.inspect)(curveTolerance)}) of "${fontFamily}" must be a positive number.`);
103
+ }
104
+ const outputDir = set.outputDir
105
+ ? path_1.default.resolve(projectRoot, set.outputDir)
106
+ : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
107
+ const config = {
108
+ fontFamily,
109
+ upm,
110
+ safeZone,
111
+ curveTolerance,
112
+ startUnicode: set.startUnicode !== undefined
113
+ ? typeof set.startUnicode === 'string'
114
+ ? parseInt(set.startUnicode, 16)
115
+ : set.startUnicode
116
+ : DEFAULT_START_UNICODE,
117
+ linking,
118
+ web,
119
+ };
120
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
121
+ upm: config.upm,
122
+ safeZone: config.safeZone,
123
+ curveTolerance: config.curveTolerance,
124
+ startUnicode: config.startUnicode,
125
+ ...versions,
126
+ });
127
+ return {
128
+ fontFamily,
129
+ inputDir,
130
+ outputDir,
131
+ ttfPath: path_1.default.join(outputDir, `${fontFamily}.ttf`),
132
+ glyphmapPath: path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`),
133
+ woff2Path: path_1.default.join(outputDir, `${fontFamily}.woff2`),
134
+ linking,
135
+ web,
136
+ webOutput,
137
+ config,
138
+ inputHash,
139
+ svgHashByFile,
140
+ };
141
+ }
142
+ async function familyIfBuiltTheSame(set) {
143
+ const same = await (0, sameOutputs_1.buildsSameOutputs)(set.outputDir, path_1.default.basename(set.glyphmapPath), (outputDir) => (0, index_1.runFontPipeline)(set.config, { inputDir: set.inputDir, outputDir, tempDir: outputDir }, { inputHash: set.inputHash, svgHashByFile: set.svgHashByFile }));
144
+ return same
145
+ ? JSON.parse(fs_1.default.readFileSync(set.glyphmapPath, 'utf8')).m.f
146
+ : undefined;
147
+ }
148
+ /**
149
+ * The input fingerprint of each icon set: the value a build stores in its glyphmap as `m.h`.
150
+ */
151
+ function fingerprintIconSets(iconSets, projectRoot) {
152
+ const versions = {
153
+ version: (0, packageVersion_1.packageVersion)(),
154
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
155
+ };
156
+ return iconSets.map((set) => {
157
+ const { fontFamily, inputHash } = resolveIconSet(set, projectRoot, true, versions);
158
+ return { fontFamily, hash: inputHash };
159
+ });
160
+ }
161
+ /**
162
+ * Report the icon sets whose generated files are out of date, without writing anything to the project.
163
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
164
+ * the set is built into a temp dir and compared with them. With `appRoot`, a static set is also out of date
165
+ * when its font linked into that app's android/ or ios/ project differs from the generated TTF.
166
+ * With `existingOnly`, sets without a glyphmap are skipped.
167
+ */
168
+ async function checkAllFonts(iconSets, projectRoot, options) {
169
+ const versions = {
170
+ version: (0, packageVersion_1.packageVersion)(),
171
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
172
+ };
173
+ const stale = [];
174
+ for (const set of iconSets) {
175
+ const resolved = resolveIconSet(set, projectRoot, options?.withWeb ?? true, versions);
176
+ if (options?.existingOnly && !fs_1.default.existsSync(resolved.glyphmapPath)) {
177
+ continue;
178
+ }
179
+ let state = currentOutput(resolved, options?.logger);
180
+ if ('staleBecause' in state &&
181
+ state.staleBecause === STALE_REASON.inputsChanged) {
182
+ const family = await familyIfBuiltTheSame(resolved);
183
+ if (family) {
184
+ options?.logger?.succeed(`${resolved.fontFamily}.ttf is up to date: its inputs changed, but it builds the same`);
185
+ state = { family };
186
+ }
187
+ }
188
+ if ('staleBecause' in state) {
189
+ options?.logger?.fail(`${resolved.fontFamily}.ttf is out of date: ${state.staleBecause}`);
190
+ stale.push({ name: resolved.fontFamily, reason: state.staleBecause });
191
+ continue;
192
+ }
193
+ if (options?.appRoot && resolved.linking === 'static') {
194
+ const reason = (0, link_1.staleLinkedFont)(options.appRoot, state.family, resolved.ttfPath);
195
+ if (reason) {
196
+ options.logger?.fail(reason);
197
+ stale.push({ name: resolved.fontFamily, reason });
198
+ }
199
+ }
55
200
  }
56
- return undefined;
201
+ return stale;
57
202
  }
58
203
  /**
59
204
  * Build TTF + glyphmap for all icon sets using a single PathKit instance.
@@ -63,56 +208,21 @@ function familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOut
63
208
  async function buildAllFonts(iconSets, projectRoot, options) {
64
209
  const withWeb = options?.withWeb ?? true;
65
210
  const logger = options?.logger;
66
- const version = (0, packageVersion_1.packageVersion)();
67
- const toolchain = (0, packageVersion_1.fontToolchainVersions)();
211
+ const versions = {
212
+ version: (0, packageVersion_1.packageVersion)(),
213
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
214
+ };
68
215
  const results = [];
69
216
  const failures = [];
70
217
  let allSkipped = true;
71
218
  for (let i = 0; i < iconSets.length; i++) {
72
- const set = iconSets[i];
73
- const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
74
- const fontFamily = set.fontFamily ?? path_1.default.basename(inputDir);
75
- const linking = set.linking ?? 'static';
76
- const web = (set.web ?? false) && withWeb;
77
- const webOutput = webOutputFor(set.web ?? false, withWeb);
78
- if (!fs_1.default.existsSync(inputDir)) {
79
- throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
80
- }
81
- const upm = set.upm ?? DEFAULT_UPM;
82
- const safeZone = set.safeZone ?? Math.round(upm * DEFAULT_SAFE_ZONE_RATIO);
83
- if (safeZone > upm) {
84
- throw new Error(`[react-native-nano-icons] safeZone (${safeZone}) of "${fontFamily}" must not exceed upm (${upm}).`);
85
- }
86
- const outputDir = set.outputDir
87
- ? path_1.default.resolve(projectRoot, set.outputDir)
88
- : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
89
- const ttfPath = path_1.default.join(outputDir, `${fontFamily}.ttf`);
90
- const glyphmapPath = path_1.default.join(outputDir, `${fontFamily}.glyphmap.json`);
91
- const woff2Path = path_1.default.join(outputDir, `${fontFamily}.woff2`);
92
- const config = {
93
- fontFamily,
94
- upm,
95
- safeZone,
96
- startUnicode: set.startUnicode !== undefined
97
- ? typeof set.startUnicode === 'string'
98
- ? parseInt(set.startUnicode, 16)
99
- : set.startUnicode
100
- : DEFAULT_START_UNICODE,
101
- linking,
102
- web,
103
- };
104
- const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSvgDirSync)(inputDir, {
105
- upm: config.upm,
106
- safeZone: config.safeZone,
107
- startUnicode: config.startUnicode,
108
- version,
109
- toolchain,
110
- });
111
- const currentFamily = familyOfCurrentOutput(inputHash, outputDir, fontFamily, linking, webOutput, logger);
112
- if (currentFamily) {
219
+ const resolved = resolveIconSet(iconSets[i], projectRoot, withWeb, versions);
220
+ const { fontFamily, inputDir, outputDir, ttfPath, glyphmapPath, woff2Path, linking, web, webOutput, config, inputHash, svgHashByFile, } = resolved;
221
+ const current = currentOutput(resolved, logger);
222
+ if ('family' in current) {
113
223
  results.push({
114
224
  fontFamily,
115
- family: currentFamily,
225
+ family: current.family,
116
226
  ttfPath,
117
227
  glyphmapPath,
118
228
  linking,
@@ -3,6 +3,7 @@ import type { SvgWorkerPool } from '../src/core/pipeline/iconPool';
3
3
  import type { SymbolTask } from '../src/core/pipeline/prepareSymbol';
4
4
  import type { PreparedSvgCache } from '../src/core/pipeline/preparedSvgCache';
5
5
  import type { NanoLogger } from './logger';
6
+ import type { StaleSet } from './build';
6
7
  export type SymbolSetConfig = {
7
8
  /** Folder of SVG files (relative to project root). */
8
9
  inputDir: string;
@@ -18,6 +19,22 @@ export declare class SymbolSetBuildError extends Error {
18
19
  built: BuiltSymbolSet[];
19
20
  constructor(message: string, built: BuiltSymbolSet[]);
20
21
  }
22
+ /**
23
+ * The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
24
+ */
25
+ export declare function fingerprintSymbolSets(symbolSets: SymbolSetConfig[], projectRoot: string): {
26
+ name: string;
27
+ hash: string;
28
+ }[];
29
+ /**
30
+ * Report the symbol sets whose generated files are out of date, without writing anything to the project.
31
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
32
+ * the set is built into a temp dir and compared with them. With `existingOnly`, sets without a symbolmap are skipped.
33
+ */
34
+ export declare function checkAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
35
+ logger?: NanoLogger;
36
+ existingOnly?: boolean;
37
+ }): Promise<StaleSet[]>;
21
38
  export declare function buildAllSymbols(symbolSets: SymbolSetConfig[], projectRoot: string, options?: {
22
39
  logger?: NanoLogger;
23
40
  keepOutputsOnFailure?: boolean;
@@ -4,10 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SymbolSetBuildError = void 0;
7
+ exports.fingerprintSymbolSets = fingerprintSymbolSets;
8
+ exports.checkAllSymbols = checkAllSymbols;
7
9
  exports.buildAllSymbols = buildAllSymbols;
8
10
  const path_1 = __importDefault(require("path"));
9
11
  const fs_1 = __importDefault(require("fs"));
10
12
  const runSymbolPipeline_1 = require("../src/core/pipeline/runSymbolPipeline");
13
+ const sameOutputs_1 = require("./sameOutputs");
11
14
  const fingerPrint_1 = require("../src/utils/fingerPrint");
12
15
  const naming_1 = require("../src/utils/naming");
13
16
  const packageVersion_1 = require("../src/utils/packageVersion");
@@ -20,26 +23,32 @@ class SymbolSetBuildError extends Error {
20
23
  }
21
24
  exports.SymbolSetBuildError = SymbolSetBuildError;
22
25
  const DEFAULT_PREFIX = 'nano';
23
- function shouldSkipGeneration(inputHash, outputDir, name, logger) {
26
+ const STALE_REASON = {
27
+ missing: (file) => `${file} is missing`,
28
+ invalidJson: (file) => `${file} is not valid JSON`,
29
+ inputsChanged: 'its SVGs, prefix or installed versions changed',
30
+ };
31
+ function currentSymbolOutput(inputHash, outputDir, name, logger) {
24
32
  const symbolmapPath = path_1.default.join(outputDir, `${name}.symbolmap.json`);
25
33
  const dtsPath = path_1.default.join(outputDir, `${name}.symbols.d.ts`);
26
34
  const symbolsDir = path_1.default.join(outputDir, `${name}.symbols`);
27
35
  const drawablesDir = path_1.default.join(outputDir, `${name}.drawables`);
28
- if (!fs_1.default.existsSync(symbolmapPath) ||
29
- !fs_1.default.existsSync(dtsPath) ||
30
- !fs_1.default.existsSync(symbolsDir) ||
31
- !fs_1.default.existsSync(drawablesDir)) {
32
- return null;
36
+ const missing = [symbolmapPath, dtsPath, symbolsDir, drawablesDir].find((file) => !fs_1.default.existsSync(file));
37
+ if (missing) {
38
+ return { staleBecause: STALE_REASON.missing(path_1.default.basename(missing)) };
33
39
  }
34
40
  let symbolmap;
35
41
  try {
36
42
  symbolmap = JSON.parse(fs_1.default.readFileSync(symbolmapPath, 'utf8'));
37
43
  }
38
44
  catch {
39
- return null;
45
+ return {
46
+ staleBecause: STALE_REASON.invalidJson(path_1.default.basename(symbolmapPath)),
47
+ };
48
+ }
49
+ if (!symbolmap?.m?.h || symbolmap.m.h !== inputHash) {
50
+ return { staleBecause: STALE_REASON.inputsChanged };
40
51
  }
41
- if (!symbolmap?.m?.h || symbolmap.m.h !== inputHash)
42
- return null;
43
52
  const symbols = symbolmap.s ?? {};
44
53
  const drawables = symbolmap.d ?? {};
45
54
  const assetDirs = Object.values(symbols).map((assetName) => path_1.default.join(symbolsDir, `${assetName}.symbolset`));
@@ -47,54 +56,106 @@ function shouldSkipGeneration(inputHash, outputDir, name, logger) {
47
56
  path_1.default.join(drawablesDir, `${resourceName}.xml`),
48
57
  path_1.default.join(drawablesDir, `${(0, naming_1.toOriginalDrawableResourceName)(resourceName)}.xml`),
49
58
  ]);
50
- if (!assetDirs.every((d) => fs_1.default.existsSync(d)))
51
- return null;
52
- if (!drawableFiles.every((f) => fs_1.default.existsSync(f)))
53
- return null;
59
+ const missingAsset = [...assetDirs, ...drawableFiles].find((file) => !fs_1.default.existsSync(file));
60
+ if (missingAsset) {
61
+ return {
62
+ staleBecause: STALE_REASON.missing(path_1.default.basename(missingAsset)),
63
+ };
64
+ }
54
65
  logger?.info(`${name}: SVG fingerprint unchanged, skipping build.`);
55
66
  return {
56
- name,
57
- prefix: symbolmap.m.p,
58
- symbolsDir,
59
- assetDirs,
60
- drawablesDir,
61
- drawableFiles,
62
- dtsPath,
63
- symbolmapPath,
64
- symbols,
65
- drawables,
67
+ built: {
68
+ name,
69
+ prefix: symbolmap.m.p,
70
+ symbolsDir,
71
+ assetDirs,
72
+ drawablesDir,
73
+ drawableFiles,
74
+ dtsPath,
75
+ symbolmapPath,
76
+ symbols,
77
+ drawables,
78
+ },
66
79
  };
67
80
  }
81
+ function resolveSymbolSet(set, projectRoot, versions) {
82
+ const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
83
+ const name = set.name ?? path_1.default.basename(inputDir);
84
+ const prefix = set.prefix ?? DEFAULT_PREFIX;
85
+ if (!fs_1.default.existsSync(inputDir)) {
86
+ throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
87
+ }
88
+ const outputDir = set.outputDir
89
+ ? path_1.default.resolve(projectRoot, set.outputDir)
90
+ : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
91
+ const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, { prefix, ...versions });
92
+ return { inputDir, name, prefix, outputDir, inputHash, svgHashByFile };
93
+ }
94
+ /**
95
+ * The input fingerprint of each symbol set: the value a build stores in its symbolmap as `m.h`.
96
+ */
97
+ function fingerprintSymbolSets(symbolSets, projectRoot) {
98
+ const versions = {
99
+ version: (0, packageVersion_1.packageVersion)(),
100
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
101
+ };
102
+ return symbolSets.map((set) => {
103
+ const { name, inputHash } = resolveSymbolSet(set, projectRoot, versions);
104
+ return { name, hash: inputHash };
105
+ });
106
+ }
107
+ /**
108
+ * Report the symbol sets whose generated files are out of date, without writing anything to the project.
109
+ * A set is out of date when a build would change its generated files. When only its input fingerprint changed,
110
+ * the set is built into a temp dir and compared with them. With `existingOnly`, sets without a symbolmap are skipped.
111
+ */
112
+ async function checkAllSymbols(symbolSets, projectRoot, options) {
113
+ const versions = {
114
+ version: (0, packageVersion_1.packageVersion)(),
115
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
116
+ };
117
+ const stale = [];
118
+ for (const set of symbolSets) {
119
+ const { inputDir, name, prefix, outputDir, inputHash, svgHashByFile } = resolveSymbolSet(set, projectRoot, versions);
120
+ if (options?.existingOnly &&
121
+ !fs_1.default.existsSync(path_1.default.join(outputDir, `${name}.symbolmap.json`))) {
122
+ continue;
123
+ }
124
+ const state = currentSymbolOutput(inputHash, outputDir, name);
125
+ if ('staleBecause' in state &&
126
+ state.staleBecause === STALE_REASON.inputsChanged &&
127
+ (await (0, sameOutputs_1.buildsSameOutputs)(outputDir, `${name}.symbolmap.json`, (dir) => (0, runSymbolPipeline_1.runSymbolPipeline)({ name, prefix }, { inputDir, outputDir: dir }, { inputHash, svgHashByFile })))) {
128
+ options?.logger?.succeed(`${name} symbols are up to date: their inputs changed, but they build the same`);
129
+ }
130
+ else if ('staleBecause' in state) {
131
+ options?.logger?.fail(`${name} symbols are out of date: ${state.staleBecause}`);
132
+ stale.push({ name, reason: state.staleBecause });
133
+ }
134
+ else {
135
+ options?.logger?.succeed(`${name} symbols are up to date`);
136
+ }
137
+ }
138
+ return stale;
139
+ }
68
140
  // Build all symbol sets. Output goes in a "nanoicons" folder next to each
69
141
  // inputDir, matching the font pipeline's convention.
70
142
  async function buildAllSymbols(symbolSets, projectRoot, options) {
71
143
  const logger = options?.logger;
72
- const version = (0, packageVersion_1.packageVersion)();
73
- const toolchain = (0, packageVersion_1.fontToolchainVersions)();
144
+ const versions = {
145
+ version: (0, packageVersion_1.packageVersion)(),
146
+ toolchain: (0, packageVersion_1.fontToolchainVersions)(),
147
+ };
74
148
  const results = [];
75
149
  const failures = [];
76
150
  for (let i = 0; i < symbolSets.length; i++) {
77
151
  const set = symbolSets[i];
78
- const inputDir = path_1.default.resolve(projectRoot, set.inputDir);
79
- const name = set.name ?? path_1.default.basename(inputDir);
80
- const prefix = set.prefix ?? DEFAULT_PREFIX;
81
- if (!fs_1.default.existsSync(inputDir)) {
82
- throw new Error(`[react-native-nano-icons] Input directory does not exist: ${inputDir} (from "${set.inputDir}")`);
83
- }
84
- const outputDir = set.outputDir
85
- ? path_1.default.resolve(projectRoot, set.outputDir)
86
- : path_1.default.join(path_1.default.dirname(inputDir), 'nanoicons');
152
+ const { inputDir, name, prefix, outputDir, inputHash, svgHashByFile } = resolveSymbolSet(set, projectRoot, versions);
87
153
  if ('multicolor' in set) {
88
154
  logger?.warn(`${name}: "multicolor" is no longer needed — every symbol now carries both rendering modes; remove it from the config.`);
89
155
  }
90
- const { hash: inputHash, svgHashByFile } = (0, fingerPrint_1.fingerprintSymbolDirSync)(inputDir, {
91
- prefix,
92
- version,
93
- toolchain,
94
- });
95
- const skipped = shouldSkipGeneration(inputHash, outputDir, name, logger);
96
- if (skipped) {
97
- results.push(skipped);
156
+ const current = currentSymbolOutput(inputHash, outputDir, name, logger);
157
+ if ('built' in current) {
158
+ results.push(current.built);
98
159
  continue;
99
160
  }
100
161
  logger?.start(`Building ${name} (${i + 1}/${symbolSets.length})…`);
@@ -8,5 +8,15 @@ import type { SymbolSetConfig } from './buildSymbols';
8
8
  * falling back to @expo/config.
9
9
  */
10
10
  export declare function loadDynamicSetsFromAppConfig(projectRoot: string): IconSetConfig[];
11
+ type NanoIconsPluginOptions = {
12
+ iconSets?: IconSetConfig[];
13
+ symbolSets?: SymbolSetConfig[];
14
+ };
11
15
  export declare function loadIconSetsFromAppConfig(projectRoot: string): IconSetConfig[];
12
16
  export declare function loadSymbolSetsFromAppConfig(projectRoot: string): SymbolSetConfig[];
17
+ /**
18
+ * The plugin options in the Expo app config, `{}` when the plugin is listed without options,
19
+ * or `undefined` when it is not listed.
20
+ */
21
+ export declare function findPluginOptions(projectRoot: string): NanoIconsPluginOptions | undefined;
22
+ export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadDynamicSetsFromAppConfig = loadDynamicSetsFromAppConfig;
4
4
  exports.loadIconSetsFromAppConfig = loadIconSetsFromAppConfig;
5
5
  exports.loadSymbolSetsFromAppConfig = loadSymbolSetsFromAppConfig;
6
+ exports.findPluginOptions = findPluginOptions;
6
7
  /**
7
8
  * Load icon sets configured with linking: 'dynamic' from the Expo app config
8
9
  * (app.json, app.config.js, or app.config.ts).
@@ -18,6 +19,11 @@ function loadDynamicSetsFromAppConfig(projectRoot) {
18
19
  }
19
20
  return dynamicSets;
20
21
  }
22
+ const PLUGIN_NAMES = [
23
+ 'react-native-nano-icons',
24
+ 'react-native-nano-icons/app.plugin',
25
+ 'react-native-nano-icons/app.plugin.js',
26
+ ];
21
27
  function loadIconSetsFromAppConfig(projectRoot) {
22
28
  return loadPluginOptions(projectRoot).iconSets ?? [];
23
29
  }
@@ -25,6 +31,18 @@ function loadSymbolSetsFromAppConfig(projectRoot) {
25
31
  return loadPluginOptions(projectRoot).symbolSets ?? [];
26
32
  }
27
33
  function loadPluginOptions(projectRoot) {
34
+ const options = findPluginOptions(projectRoot);
35
+ if (!options) {
36
+ throw new Error(`[react-native-nano-icons] Plugin "react-native-nano-icons" not found in app config.\n` +
37
+ `Add it to your app.json or app.config.js/ts under the "plugins" key.`);
38
+ }
39
+ return options;
40
+ }
41
+ /**
42
+ * The plugin options in the Expo app config, `{}` when the plugin is listed without options,
43
+ * or `undefined` when it is not listed.
44
+ */
45
+ function findPluginOptions(projectRoot) {
28
46
  const configModule = resolveExpoConfigModule(projectRoot);
29
47
  if (!configModule) {
30
48
  throw new Error(`[react-native-nano-icons] Could not find expo/config or @expo/config from ${projectRoot} — required for --dynamic-app-config.\n` +
@@ -33,13 +51,10 @@ function loadPluginOptions(projectRoot) {
33
51
  const { getConfig } = require(configModule);
34
52
  const { exp } = getConfig(projectRoot, { skipSDKVersionRequirement: true });
35
53
  const plugins = Array.isArray(exp.plugins) ? exp.plugins : [];
36
- const entry = plugins.find((p) => Array.isArray(p) && p[0] === 'react-native-nano-icons');
37
- if (!entry) {
38
- throw new Error(`[react-native-nano-icons] Plugin "react-native-nano-icons" not found in app config.\n` +
39
- `Add it to your app.json or app.config.js/ts under the "plugins" key.`);
40
- }
41
- const [, options] = entry;
42
- return options;
54
+ const entry = plugins.find((p) => PLUGIN_NAMES.includes(Array.isArray(p) ? p[0] : p));
55
+ if (!entry)
56
+ return undefined;
57
+ return (Array.isArray(entry) ? entry[1] : undefined) ?? {};
43
58
  }
44
59
  function resolveExpoConfigModule(projectRoot) {
45
60
  const candidates = [
@@ -0,0 +1,15 @@
1
+ /** An `@expo/fingerprint` hash source of type `contents`. */
2
+ export type FingerprintSource = {
3
+ type: 'contents';
4
+ id: string;
5
+ contents: string;
6
+ reasons: string[];
7
+ };
8
+ /**
9
+ * `extraSources` for `fingerprint.config.js`, read from the plugin options in the Expo app config.
10
+ * Icon sets with `linking: 'static'` and symbol sets are built into the native app, so each adds its
11
+ * input fingerprint: its SVGs, its options, and the installed library and font toolchain versions.
12
+ * Dynamic icon sets are left out, because an update delivers them.
13
+ * Returns no sources when the plugin is not configured, and warns and returns none when the sets can't be read.
14
+ */
15
+ export declare function nanoIconsFingerprintSources(projectRoot: string): FingerprintSource[];
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nanoIconsFingerprintSources = nanoIconsFingerprintSources;
4
+ const build_1 = require("./build");
5
+ const buildSymbols_1 = require("./buildSymbols");
6
+ const expoConfig_1 = require("./expoConfig");
7
+ const REASONS = ['react-native-nano-icons'];
8
+ /**
9
+ * `extraSources` for `fingerprint.config.js`, read from the plugin options in the Expo app config.
10
+ * Icon sets with `linking: 'static'` and symbol sets are built into the native app, so each adds its
11
+ * input fingerprint: its SVGs, its options, and the installed library and font toolchain versions.
12
+ * Dynamic icon sets are left out, because an update delivers them.
13
+ * Returns no sources when the plugin is not configured, and warns and returns none when the sets can't be read.
14
+ */
15
+ function nanoIconsFingerprintSources(projectRoot) {
16
+ try {
17
+ const options = (0, expoConfig_1.findPluginOptions)(projectRoot);
18
+ const iconSets = (0, build_1.fingerprintIconSets)((options?.iconSets ?? []).filter((set) => set.linking !== 'dynamic'), projectRoot).map(({ fontFamily, hash }) => ({
19
+ type: 'contents',
20
+ id: `react-native-nano-icons:iconSet:${fontFamily}`,
21
+ contents: hash,
22
+ reasons: REASONS,
23
+ }));
24
+ const symbolSets = (0, buildSymbols_1.fingerprintSymbolSets)(options?.symbolSets ?? [], projectRoot).map(({ name, hash }) => ({
25
+ type: 'contents',
26
+ id: `react-native-nano-icons:symbolSet:${name}`,
27
+ contents: hash,
28
+ reasons: REASONS,
29
+ }));
30
+ return [...iconSets, ...symbolSets];
31
+ }
32
+ catch (err) {
33
+ console.warn(`[react-native-nano-icons] No fingerprint sources added: ${err instanceof Error ? err.message : String(err)}`);
34
+ return [];
35
+ }
36
+ }
@@ -1,5 +1,5 @@
1
- export { buildAllFonts, IconSetBuildError, type IconSetConfig, type BuiltFont, } from './build';
2
- export { buildAllSymbols, SymbolSetBuildError, type SymbolSetConfig, type BuiltSymbolSet, } from './buildSymbols';
1
+ export { buildAllFonts, checkAllFonts, IconSetBuildError, type IconSetConfig, type BuiltFont, type StaleSet, } from './build';
2
+ export { buildAllSymbols, checkAllSymbols, SymbolSetBuildError, type SymbolSetConfig, type BuiltSymbolSet, } from './buildSymbols';
3
3
  export { SvgWorkerPool, type PreparedSvgCache, } from '../src/core/pipeline/index';
4
4
  export { createOraLogger, createQuietLogger, detectExpoLogLevel, type NanoLogger, type LogLevel, } from './logger';
5
5
  export { loadNanoIconsConfig, loadDynamicIconSets, type NanoIconsConfig, } from './config';
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyDrawablesIntoResDir = exports.linkBareAndroidDrawables = exports.copySymbolsetsIntoCatalog = exports.linkBareSymbols = exports.syncAndroidFontAssets = exports.linkBare = exports.loadSymbolSetsFromAppConfig = exports.loadIconSetsFromAppConfig = exports.loadDynamicSetsFromAppConfig = exports.loadDynamicIconSets = exports.loadNanoIconsConfig = exports.detectExpoLogLevel = exports.createQuietLogger = exports.createOraLogger = exports.SvgWorkerPool = exports.SymbolSetBuildError = exports.buildAllSymbols = exports.IconSetBuildError = exports.buildAllFonts = void 0;
3
+ exports.copyDrawablesIntoResDir = exports.linkBareAndroidDrawables = exports.copySymbolsetsIntoCatalog = exports.linkBareSymbols = exports.syncAndroidFontAssets = exports.linkBare = exports.loadSymbolSetsFromAppConfig = exports.loadIconSetsFromAppConfig = exports.loadDynamicSetsFromAppConfig = exports.loadDynamicIconSets = exports.loadNanoIconsConfig = exports.detectExpoLogLevel = exports.createQuietLogger = exports.createOraLogger = exports.SvgWorkerPool = exports.SymbolSetBuildError = exports.checkAllSymbols = exports.buildAllSymbols = exports.IconSetBuildError = exports.checkAllFonts = exports.buildAllFonts = void 0;
4
4
  var build_1 = require("./build");
5
5
  Object.defineProperty(exports, "buildAllFonts", { enumerable: true, get: function () { return build_1.buildAllFonts; } });
6
+ Object.defineProperty(exports, "checkAllFonts", { enumerable: true, get: function () { return build_1.checkAllFonts; } });
6
7
  Object.defineProperty(exports, "IconSetBuildError", { enumerable: true, get: function () { return build_1.IconSetBuildError; } });
7
8
  var buildSymbols_1 = require("./buildSymbols");
8
9
  Object.defineProperty(exports, "buildAllSymbols", { enumerable: true, get: function () { return buildSymbols_1.buildAllSymbols; } });
10
+ Object.defineProperty(exports, "checkAllSymbols", { enumerable: true, get: function () { return buildSymbols_1.checkAllSymbols; } });
9
11
  Object.defineProperty(exports, "SymbolSetBuildError", { enumerable: true, get: function () { return buildSymbols_1.SymbolSetBuildError; } });
10
12
  var index_1 = require("../src/core/pipeline/index");
11
13
  Object.defineProperty(exports, "SvgWorkerPool", { enumerable: true, get: function () { return index_1.SvgWorkerPool; } });