@react-native-oh/react-native-harmony-cli 0.0.27 → 0.0.30

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 (140) hide show
  1. package/README.md +12 -0
  2. package/dist/assetResolver.js +6 -0
  3. package/dist/autolinking/Autolinking.js +275 -0
  4. package/dist/autolinking/index.js +23 -0
  5. package/dist/codegen/core/CodeGenerator.js +6 -0
  6. package/dist/codegen/core/CodegenError.js +6 -0
  7. package/dist/codegen/core/EventUtils.js +6 -0
  8. package/dist/codegen/core/TypeAnnotationToTS.js +6 -0
  9. package/dist/codegen/core/UberSchema.js +9 -3
  10. package/dist/codegen/core/index.js +6 -0
  11. package/dist/codegen/generators/AppBuildTimeGlueCodeGenerator.js +6 -0
  12. package/dist/codegen/generators/ArkTSComponentCodeGeneratorArkTS.js +6 -0
  13. package/dist/codegen/generators/ArkTSComponentCodeGeneratorCAPI.js +6 -0
  14. package/dist/codegen/generators/CppComponentCodeGenerator.js +6 -0
  15. package/dist/codegen/generators/LibGlueCodeGenerator.js +6 -0
  16. package/dist/codegen/generators/NativeModuleCodeGenerator.js +6 -0
  17. package/dist/codegen/generators/SharedComponentCodeGenerator.js +6 -0
  18. package/dist/codegen/generators/UberGeneratorV1.js +6 -0
  19. package/dist/codegen/generators/UberGeneratorV2.js +6 -0
  20. package/dist/codegen/generators/index.js +6 -0
  21. package/dist/codegen/index.js +6 -0
  22. package/dist/codegen/templates/BaseComponentInstanceHTemplate.js +6 -0
  23. package/dist/codegen/templates/BasePackageHTemplate.js +6 -0
  24. package/dist/codegen/templates/ComponentDescriptorHTemplate.js +6 -0
  25. package/dist/codegen/templates/ComponentJSIBinderHTemplate.js +6 -0
  26. package/dist/codegen/templates/ComponentUtilsTSTemplate.js +6 -0
  27. package/dist/codegen/templates/IndexTSTemplate.js +6 -0
  28. package/dist/codegen/templates/RNOHGeneratedPackageHTemplate.js +6 -0
  29. package/dist/codegen/templates/TurboModuleCppTemplate.js +6 -0
  30. package/dist/codegen/templates/TurboModuleHTemplate.js +6 -0
  31. package/dist/codegen/templates/TurboModuleSpecTSTemplate.js +6 -0
  32. package/dist/codegen/templates/index.js +6 -0
  33. package/dist/commands/bundle-harmony.js +7 -1
  34. package/dist/commands/codegen-harmony.js +16 -10
  35. package/dist/commands/codegen-lib-harmony.js +6 -0
  36. package/dist/commands/create-metro-host-constants.js +6 -0
  37. package/dist/commands/index.js +7 -0
  38. package/dist/commands/link-harmony.js +97 -0
  39. package/dist/commands/pack-harmony.js +6 -0
  40. package/dist/commands/unpack-harmony.js +10 -3
  41. package/dist/commands/verify-package-harmony.js +6 -0
  42. package/dist/core/AbsolutePath.js +12 -0
  43. package/dist/core/CodegenConfig.js +6 -0
  44. package/dist/core/DescriptiveError.js +6 -0
  45. package/dist/core/FileSystem.js +33 -0
  46. package/dist/core/OHPackageJSON5.js +6 -0
  47. package/dist/core/PackageJSON.js +15 -7
  48. package/dist/core/ProjectDependenciesManager.js +31 -18
  49. package/dist/core/ValidationError.js +6 -0
  50. package/dist/core/ValueObject.js +6 -0
  51. package/dist/core/fs.js +6 -0
  52. package/dist/core/index.js +7 -0
  53. package/dist/index.js +7 -0
  54. package/dist/io/CliExecutor.js +35 -0
  55. package/dist/io/Logger.js +9 -0
  56. package/dist/io/RealFS.js +68 -0
  57. package/dist/io/TarGz.js +6 -0
  58. package/dist/io/__fixtures__.js +127 -0
  59. package/dist/io/fsUtils.js +20 -6
  60. package/dist/io/index.js +7 -0
  61. package/dist/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.js +6 -0
  62. package/dist/package-verifier/checks/HarmonyDirExistsCheck.js +6 -0
  63. package/dist/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.js +6 -0
  64. package/dist/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.js +6 -0
  65. package/dist/package-verifier/checks/index.js +6 -0
  66. package/dist/package-verifier/index.js +6 -0
  67. package/dist/package-verifier/types.js +6 -0
  68. package/dist/package-verifier/verify-package.js +7 -1
  69. package/jest.config.js +7 -0
  70. package/package.json +8 -2
  71. package/react-native.config.js +7 -0
  72. package/src/assetResolver.ts +7 -0
  73. package/src/autolinking/Autolinking.test.ts +483 -0
  74. package/src/autolinking/Autolinking.ts +384 -0
  75. package/src/autolinking/index.ts +8 -0
  76. package/src/codegen/core/CodeGenerator.ts +7 -0
  77. package/src/codegen/core/CodegenError.ts +7 -0
  78. package/src/codegen/core/EventUtils.ts +7 -0
  79. package/src/codegen/core/TypeAnnotationToTS.test.ts +7 -0
  80. package/src/codegen/core/TypeAnnotationToTS.ts +7 -0
  81. package/src/codegen/core/UberSchema.ts +11 -1
  82. package/src/codegen/core/index.ts +7 -0
  83. package/src/codegen/generators/AppBuildTimeGlueCodeGenerator.ts +7 -0
  84. package/src/codegen/generators/ArkTSComponentCodeGeneratorArkTS.ts +7 -0
  85. package/src/codegen/generators/ArkTSComponentCodeGeneratorCAPI.ts +7 -0
  86. package/src/codegen/generators/CppComponentCodeGenerator.ts +7 -0
  87. package/src/codegen/generators/LibGlueCodeGenerator.ts +7 -0
  88. package/src/codegen/generators/NativeModuleCodeGenerator.ts +7 -0
  89. package/src/codegen/generators/SharedComponentCodeGenerator.ts +7 -0
  90. package/src/codegen/generators/UberGeneratorV1.ts +7 -0
  91. package/src/codegen/generators/UberGeneratorV2.ts +7 -0
  92. package/src/codegen/generators/index.ts +7 -0
  93. package/src/codegen/index.ts +7 -0
  94. package/src/codegen/templates/BaseComponentInstanceHTemplate.ts +7 -0
  95. package/src/codegen/templates/BasePackageHTemplate.ts +7 -0
  96. package/src/codegen/templates/ComponentDescriptorHTemplate.ts +7 -0
  97. package/src/codegen/templates/ComponentJSIBinderHTemplate.ts +7 -0
  98. package/src/codegen/templates/ComponentUtilsTSTemplate.ts +7 -0
  99. package/src/codegen/templates/IndexTSTemplate.ts +7 -0
  100. package/src/codegen/templates/RNOHGeneratedPackageHTemplate.ts +7 -0
  101. package/src/codegen/templates/TurboModuleCppTemplate.ts +7 -0
  102. package/src/codegen/templates/TurboModuleHTemplate.ts +7 -0
  103. package/src/codegen/templates/TurboModuleSpecTSTemplate.ts +7 -0
  104. package/src/codegen/templates/index.ts +7 -0
  105. package/src/commands/bundle-harmony.ts +8 -2
  106. package/src/commands/codegen-harmony.ts +19 -6
  107. package/src/commands/codegen-lib-harmony.ts +7 -0
  108. package/src/commands/create-metro-host-constants.ts +7 -0
  109. package/src/commands/index.ts +8 -0
  110. package/src/commands/link-harmony.ts +102 -0
  111. package/src/commands/pack-harmony.ts +7 -0
  112. package/src/commands/unpack-harmony.ts +12 -3
  113. package/src/commands/verify-package-harmony.ts +7 -0
  114. package/src/core/AbsolutePath.ts +16 -0
  115. package/src/core/CodegenConfig.ts +7 -0
  116. package/src/core/DescriptiveError.ts +7 -0
  117. package/src/core/FileSystem.ts +57 -0
  118. package/src/core/OHPackageJSON5.ts +7 -0
  119. package/src/core/PackageJSON.ts +40 -8
  120. package/src/core/ProjectDependenciesManager.ts +40 -14
  121. package/src/core/ValidationError.ts +7 -0
  122. package/src/core/ValueObject.ts +7 -0
  123. package/src/core/fs.ts +7 -0
  124. package/src/core/index.ts +8 -0
  125. package/src/index.ts +9 -0
  126. package/src/io/CliExecutor.ts +47 -0
  127. package/src/io/Logger.ts +11 -0
  128. package/src/io/RealFS.ts +62 -0
  129. package/src/io/TarGz.ts +7 -0
  130. package/src/io/__fixtures__.ts +135 -0
  131. package/src/io/fsUtils.ts +26 -6
  132. package/src/io/index.ts +8 -0
  133. package/src/package-verifier/checks/HarmonyDirContainsOnlyHarsCheck.ts +7 -0
  134. package/src/package-verifier/checks/HarmonyDirExistsCheck.ts +7 -0
  135. package/src/package-verifier/checks/NpmAnAndOhPackageVersionsAreEqual.ts +7 -0
  136. package/src/package-verifier/checks/OhPackageNameFollowsNamingConventionCheck.ts +7 -0
  137. package/src/package-verifier/checks/index.ts +7 -0
  138. package/src/package-verifier/index.ts +7 -0
  139. package/src/package-verifier/types.ts +7 -0
  140. package/src/package-verifier/verify-package.ts +9 -1
@@ -0,0 +1,483 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE-MIT file in the root directory of this source tree.
6
+ */
7
+
8
+ import { Autolinking, AutolinkingConfig } from './Autolinking';
9
+ import { NestedDirectoryJSON } from 'memfs';
10
+ import { AbsolutePath, DescriptiveError } from '../core';
11
+ import { MockedLogger, MemFS } from '../io/__fixtures__';
12
+
13
+ function createAutolinking({
14
+ fsStructure,
15
+ }: {
16
+ fsStructure: NestedDirectoryJSON;
17
+ }) {
18
+ const memFS = new MemFS(fsStructure);
19
+ const mockedLogger = new MockedLogger();
20
+ const autolinking = new Autolinking(memFS, mockedLogger);
21
+
22
+ return {
23
+ runAutolinking: async (config: Partial<AutolinkingConfig> = {}) => {
24
+ const input = await autolinking.prepareInput({
25
+ harmonyProjectPath:
26
+ config.harmonyProjectPath ?? new AbsolutePath('./harmony'),
27
+ nodeModulesPath:
28
+ config.nodeModulesPath ?? new AbsolutePath('./node_modules'),
29
+ cppRNOHPackagesFactoryPathRelativeToHarmony:
30
+ config.cppRNOHPackagesFactoryPathRelativeToHarmony ??
31
+ './entry/src/main/cpp/RNOHPackageFactory.h',
32
+ ohPackagePathRelativeToHarmony:
33
+ config.ohPackagePathRelativeToHarmony ?? './oh-package.json5',
34
+ etsRNOHPackagesFactoryPathRelativeToHarmony:
35
+ config.etsRNOHPackagesFactoryPathRelativeToHarmony ??
36
+ './entry/src/main/ets/RNOHPackageFactory.ets',
37
+ cmakeAutolinkPathRelativeToHarmony:
38
+ config.cmakeAutolinkPathRelativeToHarmony ??
39
+ './entry/src/main/cpp/autolink.cmake',
40
+ excludedNpmPackageNames: config.excludedNpmPackageNames ?? new Set(),
41
+ includedNpmPackageNames: config.includedNpmPackageNames ?? new Set(),
42
+ });
43
+ const output = autolinking.evaluate(input);
44
+ autolinking.saveAndLogOutput(output);
45
+ return {
46
+ cmakeAutolinkingPath: output.cmakeAutolinkingPathAndContent[0],
47
+ cppRNOHPackagesFactoryPath:
48
+ output.cppRNOHPackagesFactoryPathAndContent[0],
49
+ etsRNOHPackagesFactoryPath:
50
+ output.etsRNOHPackagesFactoryPathAndContent[0],
51
+ ohPackagePath: output.ohPackagePathAndContent[0],
52
+ logs: mockedLogger.getLogs(),
53
+ };
54
+ },
55
+ memFS,
56
+ };
57
+ }
58
+
59
+ const baseFileStructure = {
60
+ harmony: {
61
+ entry: {
62
+ src: {
63
+ main: {
64
+ ets: {},
65
+ cpp: {},
66
+ },
67
+ },
68
+ },
69
+ 'oh-package.json5': `{
70
+ "dependencies": {
71
+ }
72
+ }`,
73
+ },
74
+ };
75
+
76
+ it('should generate correct templates with scoped package default configuration', async () => {
77
+ const { runAutolinking, memFS } = createAutolinking({
78
+ fsStructure: {
79
+ ...baseFileStructure,
80
+ node_modules: {
81
+ '@rnoh': {
82
+ 'link-scoped': {
83
+ harmony: {
84
+ 'link_scoped.har': '',
85
+ },
86
+ 'package.json': JSON.stringify({
87
+ name: '@rnoh/link-scoped',
88
+ harmony: {
89
+ autolinking: true,
90
+ },
91
+ }),
92
+ },
93
+ },
94
+ },
95
+ },
96
+ });
97
+
98
+ await runAutolinking();
99
+
100
+ expect(
101
+ memFS.readTextSync(new AbsolutePath('./harmony/oh-package.json5'))
102
+ ).toBe(
103
+ `
104
+ {
105
+ dependencies: {
106
+ "@rnoh/rnoh--link-scoped": "file:../node_modules/@rnoh/link-scoped/harmony/link_scoped.har",
107
+ },
108
+ }
109
+ `.trimStart()
110
+ );
111
+ expect(
112
+ memFS.readTextSync(
113
+ new AbsolutePath('./harmony/entry/src/main/ets/RNOHPackageFactory.ets')
114
+ )
115
+ ).toBe(
116
+ `
117
+ /*
118
+ * This file was generated by RNOH autolinking.
119
+ * DO NOT modify it manually, your changes WILL be overwritten.
120
+ */
121
+ import type { RNPackageContext, RNOHPackage } from '@rnoh/react-native-openharmony';
122
+ import RnohLinkScopedPackage from '@rnoh/rnoh--link-scoped';
123
+
124
+ export function createRNOHPackages(ctx: RNPackageContext): RNOHPackage[] {
125
+ return [
126
+ new RnohLinkScopedPackage(ctx),
127
+ ];
128
+ }
129
+ `.trimStart()
130
+ );
131
+
132
+ expect(
133
+ memFS.readTextSync(
134
+ new AbsolutePath('./harmony/entry/src/main/cpp/RNOHPackageFactory.h')
135
+ )
136
+ ).toBe(
137
+ `
138
+ /*
139
+ * This file was generated by RNOH autolinking.
140
+ * DO NOT modify it manually, your changes WILL be overwritten.
141
+ */
142
+ // clang-format off
143
+ #pragma once
144
+ #include "RNOH/Package.h"
145
+ #include "RnohLinkScopedPackage.h"
146
+
147
+ std::vector<rnoh::Package::Shared> createRNOHPackages(const rnoh::Package::Context &ctx) {
148
+ return {
149
+ std::make_shared<rnoh::RnohLinkScopedPackage>(ctx),
150
+ };
151
+ }
152
+ `.trimStart()
153
+ );
154
+
155
+ expect(
156
+ memFS.readTextSync(
157
+ new AbsolutePath('./harmony/entry/src/main/cpp/autolink.cmake')
158
+ )
159
+ ).toBe(
160
+ `
161
+ # This file was generated by RNOH autolinking.
162
+ # DO NOT modify it manually, your changes WILL be overwritten.
163
+ cmake_minimum_required(VERSION 3.5)
164
+
165
+ # @api
166
+ function(autolink_libraries target)
167
+ add_subdirectory("\${OH_MODULES_DIR}/@rnoh/rnoh--link-scoped/src/main/cpp" ./rnoh__rnoh__link_scoped)
168
+
169
+ set(AUTOLINKED_LIBRARIES
170
+ rnoh__rnoh__link_scoped
171
+ )
172
+
173
+ foreach(lib \${AUTOLINKED_LIBRARIES})
174
+ target_link_libraries(\${target} PUBLIC \${lib})
175
+ endforeach()
176
+ endfunction()
177
+ `.trimStart()
178
+ );
179
+ });
180
+
181
+ it('should handle custom autolinking configuration', async () => {
182
+ const { runAutolinking, memFS } = createAutolinking({
183
+ fsStructure: {
184
+ ...baseFileStructure,
185
+ node_modules: {
186
+ '@rnoh': {
187
+ 'custom-config': {
188
+ harmony: {
189
+ 'custom_config.har': '',
190
+ },
191
+ 'package.json': JSON.stringify({
192
+ name: '@rnoh/custom-config',
193
+ harmony: {
194
+ autolinking: {
195
+ ohPackageName: '@rnoh/custom-oh-name',
196
+ etsPackageClassName: 'CustomEtsClass',
197
+ cppPackageClassName: 'CustomCppClass',
198
+ cmakeLibraryTargetName: 'custom_cmake_target',
199
+ },
200
+ },
201
+ }),
202
+ },
203
+ },
204
+ },
205
+ },
206
+ });
207
+
208
+ const output = await runAutolinking();
209
+
210
+ expect(memFS.readTextSync(output.etsRNOHPackagesFactoryPath)).toContain(
211
+ 'CustomEtsClass'
212
+ );
213
+ expect(memFS.readTextSync(output.cppRNOHPackagesFactoryPath)).toContain(
214
+ 'CustomCppClass'
215
+ );
216
+ expect(memFS.readTextSync(output.cmakeAutolinkingPath)).toContain(
217
+ 'custom_cmake_target'
218
+ );
219
+ expect(memFS.readTextSync(output.ohPackagePath)).toContain(
220
+ '@rnoh/custom-oh-name'
221
+ );
222
+ });
223
+
224
+ it('should handle unscoped package correctly', async () => {
225
+ const { runAutolinking, memFS } = createAutolinking({
226
+ fsStructure: {
227
+ ...baseFileStructure,
228
+ node_modules: {
229
+ 'unscoped-package': {
230
+ harmony: {
231
+ 'unscoped_package.har': '',
232
+ },
233
+ 'package.json': JSON.stringify({
234
+ name: 'unscoped-package',
235
+ harmony: {
236
+ autolinking: true,
237
+ },
238
+ }),
239
+ },
240
+ },
241
+ },
242
+ });
243
+
244
+ const output = await runAutolinking();
245
+
246
+ expect(memFS.readTextSync(output.etsRNOHPackagesFactoryPath)).toContain(
247
+ 'UnscopedPackage'
248
+ );
249
+ expect(memFS.readTextSync(output.cppRNOHPackagesFactoryPath)).toContain(
250
+ 'UnscopedPackage'
251
+ );
252
+ expect(memFS.readTextSync(output.ohPackagePath)).toContain(
253
+ '@rnoh/unscoped-package'
254
+ );
255
+ });
256
+
257
+ it('should remove entries to missing hars from oh-package.json5 and preserve custom entries not managed by autolinking', async () => {
258
+ const { runAutolinking, memFS } = createAutolinking({
259
+ fsStructure: {
260
+ ...baseFileStructure,
261
+ node_modules: {
262
+ '@rnoh': {
263
+ 'existing-har': {
264
+ harmony: {
265
+ 'existing_har.har': '',
266
+ },
267
+ 'package.json': JSON.stringify({
268
+ name: '@rnoh/existing-har',
269
+ harmony: {
270
+ autolinking: null,
271
+ },
272
+ }),
273
+ },
274
+ 'missing-har': {
275
+ harmony: {
276
+ // No .har file here
277
+ },
278
+ 'package.json': JSON.stringify({
279
+ name: '@rnoh/missing-har',
280
+ }),
281
+ },
282
+ },
283
+ },
284
+ harmony: {
285
+ ...baseFileStructure.harmony,
286
+ 'oh-package.json5': `{
287
+ "dependencies": {
288
+ "@rnoh/existing-har": "file:../node_modules/@rnoh/existing-har/harmony/existing_har.har",
289
+ "@rnoh/missing-har": "file:../node_modules/@rnoh/missing-har/harmony/missing_har.har"
290
+ }
291
+ }`,
292
+ },
293
+ },
294
+ });
295
+
296
+ const output = await runAutolinking();
297
+
298
+ const ohPackageContent = memFS.readTextSync(output.ohPackagePath);
299
+ expect(ohPackageContent).toContain('@rnoh/existing-har');
300
+ expect(ohPackageContent).not.toContain('@rnoh/missing-har');
301
+ });
302
+
303
+ it('should log updated files', async () => {
304
+ const { runAutolinking } = createAutolinking({
305
+ fsStructure: {
306
+ ...baseFileStructure,
307
+ node_modules: {
308
+ 'unscoped-package': {
309
+ harmony: {
310
+ 'unscoped_package.har': '',
311
+ },
312
+ 'package.json': JSON.stringify({
313
+ name: 'unscoped-package',
314
+ harmony: {
315
+ autolinking: true,
316
+ },
317
+ }),
318
+ },
319
+ },
320
+ },
321
+ });
322
+
323
+ const { logs } = await runAutolinking();
324
+
325
+ const combinedLogs = logs.map((log) => log.msg).join('\n');
326
+ expect(combinedLogs).toContain('harmony/entry/src/main/cpp/autolink.cmake');
327
+ expect(combinedLogs).toContain(
328
+ 'harmony/entry/src/main/ets/RNOHPackageFactory.ets'
329
+ );
330
+ expect(combinedLogs).toContain(
331
+ 'harmony/entry/src/main/cpp/RNOHPackageFactory.h'
332
+ );
333
+ expect(combinedLogs).toContain('harmony/oh-package.json5');
334
+ });
335
+
336
+ it('should log linked and skipped packages', async () => {
337
+ const { runAutolinking } = createAutolinking({
338
+ fsStructure: {
339
+ ...baseFileStructure,
340
+ node_modules: {
341
+ 'autolinkable-package': {
342
+ harmony: {
343
+ 'autolinkable_package.har': '',
344
+ },
345
+ 'package.json': JSON.stringify({
346
+ name: 'autolinkable-package',
347
+ harmony: {
348
+ autolinking: true,
349
+ },
350
+ }),
351
+ },
352
+ 'ignored-package': {
353
+ harmony: {
354
+ 'ignored_package.har': '',
355
+ },
356
+ 'package.json': JSON.stringify({
357
+ name: 'ignored-package',
358
+ harmony: {
359
+ autolinking: true,
360
+ },
361
+ }),
362
+ },
363
+ },
364
+ },
365
+ });
366
+
367
+ const { logs } = await runAutolinking({
368
+ excludedNpmPackageNames: new Set<string>().add('ignored-package'),
369
+ });
370
+
371
+ const combinedLogs = logs.map((log) => log.msg).join('\n');
372
+ expect(combinedLogs).toContain('[link] autolinkable-package');
373
+ expect(combinedLogs).toContain('[skip] ignored-package');
374
+ });
375
+
376
+ it('should fail when user lists included and excluded packages', async () => {
377
+ const { runAutolinking } = createAutolinking({
378
+ fsStructure: {
379
+ ...baseFileStructure,
380
+ node_modules: {
381
+ 'autolinkable-package': {
382
+ harmony: {
383
+ 'autolinkable_package.har': '',
384
+ },
385
+ 'package.json': JSON.stringify({
386
+ name: 'autolinkable-package',
387
+ }),
388
+ },
389
+ 'ignored-package': {
390
+ harmony: {
391
+ 'ignored_package.har': '',
392
+ },
393
+ 'package.json': JSON.stringify({
394
+ name: 'ignored-package',
395
+ }),
396
+ },
397
+ },
398
+ },
399
+ });
400
+
401
+ expect(() =>
402
+ runAutolinking({
403
+ includedNpmPackageNames: new Set<string>().add('autolinkable-package'),
404
+ excludedNpmPackageNames: new Set<string>().add('autolinkable-package'),
405
+ })
406
+ ).rejects.toThrow(DescriptiveError);
407
+ });
408
+
409
+ it('should link only specified packages', async () => {
410
+ const { runAutolinking } = createAutolinking({
411
+ fsStructure: {
412
+ ...baseFileStructure,
413
+ node_modules: {
414
+ 'autolinkable-package': {
415
+ harmony: {
416
+ 'autolinkable_package.har': '',
417
+ },
418
+ 'package.json': JSON.stringify({
419
+ name: 'autolinkable-package',
420
+ harmony: {
421
+ autolinking: true,
422
+ },
423
+ }),
424
+ },
425
+ 'ignored-package': {
426
+ harmony: {
427
+ 'ignored_package.har': '',
428
+ },
429
+ 'package.json': JSON.stringify({
430
+ name: 'ignored-package',
431
+ harmony: {
432
+ autolinking: true,
433
+ },
434
+ }),
435
+ },
436
+ },
437
+ },
438
+ });
439
+
440
+ const { logs } = await runAutolinking({
441
+ includedNpmPackageNames: new Set<string>().add('autolinkable-package'),
442
+ });
443
+
444
+ const combinedLogs = logs.map((log) => log.msg).join('\n');
445
+ expect(combinedLogs).toContain('[link] autolinkable-package');
446
+ expect(combinedLogs).toContain('[skip] ignored-package');
447
+ });
448
+
449
+
450
+ it('should link by default only those packages that support autolinking', async () => {
451
+ const { runAutolinking } = createAutolinking({
452
+ fsStructure: {
453
+ ...baseFileStructure,
454
+ node_modules: {
455
+ 'autolinkable-package': {
456
+ harmony: {
457
+ 'autolinkable_package.har': '',
458
+ },
459
+ 'package.json': JSON.stringify({
460
+ name: 'autolinkable-package',
461
+ harmony: {
462
+ autolinking: true,
463
+ },
464
+ }),
465
+ },
466
+ 'not-autolinkable-package': {
467
+ harmony: {
468
+ 'not_autolinkable_package.har': '',
469
+ },
470
+ 'package.json': JSON.stringify({
471
+ name: 'not-autolinkable-package',
472
+ }),
473
+ },
474
+ },
475
+ },
476
+ });
477
+
478
+ const { logs } = await runAutolinking({});
479
+
480
+ const combinedLogs = logs.map((log) => log.msg).join('\n');
481
+ expect(combinedLogs).toContain('[link] autolinkable-package');
482
+ expect(combinedLogs).toContain('[skip] not-autolinkable-package');
483
+ });