@servicenow/sdk-build-core 3.0.3 → 4.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/dist/app.d.ts +25 -0
- package/dist/app.js +8 -0
- package/dist/app.js.map +1 -0
- package/dist/compiler.d.ts +60 -0
- package/dist/compiler.js +320 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compression.d.ts +7 -0
- package/dist/compression.js +79 -0
- package/dist/compression.js.map +1 -0
- package/dist/crypto.d.ts +1 -0
- package/dist/crypto.js +9 -0
- package/dist/crypto.js.map +1 -0
- package/dist/diagnostic.d.ts +41 -0
- package/dist/diagnostic.js +130 -0
- package/dist/diagnostic.js.map +1 -0
- package/dist/{plugins/Diagnostic.d.ts → fluent-diagnostic.d.ts} +3 -2
- package/dist/fluent-diagnostic.js +23 -0
- package/dist/fluent-diagnostic.js.map +1 -0
- package/dist/fluent-directive.d.ts +8 -0
- package/dist/fluent-directive.js +54 -0
- package/dist/fluent-directive.js.map +1 -0
- package/dist/fluent-file.d.ts +5 -0
- package/dist/fluent-file.js +15 -0
- package/dist/fluent-file.js.map +1 -0
- package/dist/formatter.d.ts +11 -0
- package/dist/formatter.js +77 -0
- package/dist/formatter.js.map +1 -0
- package/dist/fs.d.ts +174 -0
- package/dist/fs.js +313 -0
- package/dist/fs.js.map +1 -0
- package/dist/guid.d.ts +2 -0
- package/dist/{GUID.js → guid.js} +3 -6
- package/dist/guid.js.map +1 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +5 -0
- package/dist/json.js +43 -0
- package/dist/json.js.map +1 -0
- package/dist/keys-registry.d.ts +64 -0
- package/dist/keys-registry.js +339 -0
- package/dist/keys-registry.js.map +1 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +17 -0
- package/dist/logger.js.map +1 -0
- package/dist/now-config.d.ts +348 -0
- package/dist/now-config.js +283 -0
- package/dist/now-config.js.map +1 -0
- package/dist/path.d.ts +3 -0
- package/dist/path.js +12 -0
- package/dist/path.js.map +1 -0
- package/dist/plugins/cache.d.ts +20 -0
- package/dist/plugins/cache.js +46 -0
- package/dist/plugins/cache.js.map +1 -0
- package/dist/plugins/context.d.ts +85 -0
- package/dist/plugins/{Context.js → context.js} +1 -1
- package/dist/plugins/context.js.map +1 -0
- package/dist/plugins/database.d.ts +27 -0
- package/dist/plugins/database.js +102 -0
- package/dist/plugins/database.js.map +1 -0
- package/dist/plugins/file.d.ts +10 -0
- package/dist/plugins/{behaviors/Arranger.js → file.js} +1 -1
- package/dist/plugins/file.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -5
- package/dist/plugins/index.js +9 -6
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/plugin.d.ts +478 -0
- package/dist/plugins/plugin.js +533 -0
- package/dist/plugins/plugin.js.map +1 -0
- package/dist/plugins/product.d.ts +15 -0
- package/dist/plugins/product.js +38 -0
- package/dist/plugins/product.js.map +1 -0
- package/dist/plugins/project.d.ts +25 -0
- package/dist/plugins/{behaviors/Generator.js → project.js} +1 -1
- package/dist/plugins/project.js.map +1 -0
- package/dist/plugins/shape.d.ts +424 -0
- package/dist/plugins/shape.js +1181 -0
- package/dist/plugins/shape.js.map +1 -0
- package/dist/plugins/time.d.ts +12 -0
- package/dist/plugins/time.js +84 -0
- package/dist/plugins/time.js.map +1 -0
- package/dist/plugins/usage.d.ts +11 -0
- package/dist/plugins/usage.js +26 -0
- package/dist/plugins/usage.js.map +1 -0
- package/dist/prettier/config-loader.d.ts +13 -0
- package/dist/prettier/config-loader.js +105 -0
- package/dist/prettier/config-loader.js.map +1 -0
- package/dist/telemetry/index.d.ts +25 -0
- package/dist/telemetry/index.js +18 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/typescript.d.ts +293 -0
- package/dist/typescript.js +454 -0
- package/dist/typescript.js.map +1 -0
- package/dist/util/get-file-type.d.ts +2 -0
- package/dist/util/get-file-type.js +13 -0
- package/dist/util/get-file-type.js.map +1 -0
- package/dist/util/index.d.ts +2 -6
- package/dist/util/index.js +2 -6
- package/dist/util/index.js.map +1 -1
- package/dist/util/{Scope.js → is-sn-scope.js} +1 -1
- package/dist/util/is-sn-scope.js.map +1 -0
- package/dist/xml.d.ts +24 -0
- package/dist/xml.js +71 -0
- package/dist/xml.js.map +1 -0
- package/now.config.schema.json +336 -0
- package/package.json +22 -12
- package/src/app.ts +33 -0
- package/src/compiler.ts +384 -0
- package/src/compression.ts +93 -0
- package/src/crypto.ts +5 -0
- package/src/diagnostic.ts +108 -0
- package/src/{plugins/Diagnostic.ts → fluent-diagnostic.ts} +3 -10
- package/src/fluent-directive.ts +63 -0
- package/src/fluent-file.ts +13 -0
- package/src/formatter.ts +58 -0
- package/src/fs.ts +438 -0
- package/src/{GUID.ts → guid.ts} +2 -6
- package/src/index.ts +19 -5
- package/src/json.ts +20 -0
- package/src/keys-registry.ts +384 -0
- package/src/logger.ts +20 -0
- package/src/now-config.ts +337 -0
- package/src/path.ts +9 -0
- package/src/plugins/cache.ts +45 -0
- package/src/plugins/context.ts +93 -0
- package/src/plugins/database.ts +121 -0
- package/src/plugins/file.ts +19 -0
- package/src/plugins/index.ts +9 -5
- package/src/plugins/plugin.ts +995 -0
- package/src/plugins/product.ts +44 -0
- package/src/plugins/project.ts +39 -0
- package/src/plugins/shape.ts +1532 -0
- package/src/plugins/time.ts +108 -0
- package/src/plugins/usage.ts +26 -0
- package/src/prettier/config-loader.ts +130 -0
- package/src/telemetry/index.ts +27 -0
- package/src/typescript.ts +502 -0
- package/src/util/get-file-type.ts +11 -0
- package/src/util/index.ts +2 -6
- package/src/xml.ts +86 -0
- package/dist/GUID.d.ts +0 -2
- package/dist/GUID.js.map +0 -1
- package/dist/IncludePaths.d.ts +0 -25
- package/dist/IncludePaths.js +0 -97
- package/dist/IncludePaths.js.map +0 -1
- package/dist/Keys.d.ts +0 -32
- package/dist/Keys.js +0 -245
- package/dist/Keys.js.map +0 -1
- package/dist/TypeScript.d.ts +0 -5
- package/dist/TypeScript.js +0 -58
- package/dist/TypeScript.js.map +0 -1
- package/dist/XML.d.ts +0 -32
- package/dist/XML.js +0 -83
- package/dist/XML.js.map +0 -1
- package/dist/plugins/Context.d.ts +0 -190
- package/dist/plugins/Context.js.map +0 -1
- package/dist/plugins/Diagnostic.js +0 -28
- package/dist/plugins/Diagnostic.js.map +0 -1
- package/dist/plugins/Plugin.d.ts +0 -175
- package/dist/plugins/Plugin.js +0 -15
- package/dist/plugins/Plugin.js.map +0 -1
- package/dist/plugins/behaviors/Arranger.d.ts +0 -26
- package/dist/plugins/behaviors/Arranger.js.map +0 -1
- package/dist/plugins/behaviors/Composer.d.ts +0 -102
- package/dist/plugins/behaviors/Composer.js +0 -15
- package/dist/plugins/behaviors/Composer.js.map +0 -1
- package/dist/plugins/behaviors/Diagnostics.d.ts +0 -7
- package/dist/plugins/behaviors/Diagnostics.js +0 -3
- package/dist/plugins/behaviors/Diagnostics.js.map +0 -1
- package/dist/plugins/behaviors/Generator.d.ts +0 -21
- package/dist/plugins/behaviors/Generator.js.map +0 -1
- package/dist/plugins/behaviors/OwnedTables.d.ts +0 -6
- package/dist/plugins/behaviors/OwnedTables.js +0 -3
- package/dist/plugins/behaviors/OwnedTables.js.map +0 -1
- package/dist/plugins/behaviors/PostProcessor.d.ts +0 -5
- package/dist/plugins/behaviors/PostProcessor.js +0 -3
- package/dist/plugins/behaviors/PostProcessor.js.map +0 -1
- package/dist/plugins/behaviors/Serializer.d.ts +0 -30
- package/dist/plugins/behaviors/Serializer.js +0 -3
- package/dist/plugins/behaviors/Serializer.js.map +0 -1
- package/dist/plugins/behaviors/Transformer.d.ts +0 -23
- package/dist/plugins/behaviors/Transformer.js +0 -3
- package/dist/plugins/behaviors/Transformer.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Data.d.ts +0 -119
- package/dist/plugins/behaviors/extractors/Data.js +0 -244
- package/dist/plugins/behaviors/extractors/Data.js.map +0 -1
- package/dist/plugins/behaviors/extractors/Extractors.d.ts +0 -63
- package/dist/plugins/behaviors/extractors/Extractors.js +0 -3
- package/dist/plugins/behaviors/extractors/Extractors.js.map +0 -1
- package/dist/plugins/behaviors/extractors/index.d.ts +0 -2
- package/dist/plugins/behaviors/extractors/index.js +0 -19
- package/dist/plugins/behaviors/extractors/index.js.map +0 -1
- package/dist/plugins/behaviors/index.d.ts +0 -9
- package/dist/plugins/behaviors/index.js +0 -26
- package/dist/plugins/behaviors/index.js.map +0 -1
- package/dist/plugins/util/CallExpression.d.ts +0 -5
- package/dist/plugins/util/CallExpression.js +0 -88
- package/dist/plugins/util/CallExpression.js.map +0 -1
- package/dist/plugins/util/CodeTransformation.d.ts +0 -95
- package/dist/plugins/util/CodeTransformation.js +0 -624
- package/dist/plugins/util/CodeTransformation.js.map +0 -1
- package/dist/plugins/util/ObjectLiteral.d.ts +0 -9
- package/dist/plugins/util/ObjectLiteral.js +0 -37
- package/dist/plugins/util/ObjectLiteral.js.map +0 -1
- package/dist/plugins/util/index.d.ts +0 -3
- package/dist/plugins/util/index.js +0 -20
- package/dist/plugins/util/index.js.map +0 -1
- package/dist/util/Debug.d.ts +0 -4
- package/dist/util/Debug.js +0 -20
- package/dist/util/Debug.js.map +0 -1
- package/dist/util/Directive.d.ts +0 -16
- package/dist/util/Directive.js +0 -107
- package/dist/util/Directive.js.map +0 -1
- package/dist/util/RuntimeTableSchema.d.ts +0 -5
- package/dist/util/RuntimeTableSchema.js +0 -58
- package/dist/util/RuntimeTableSchema.js.map +0 -1
- package/dist/util/Scope.js.map +0 -1
- package/dist/util/Util.d.ts +0 -1
- package/dist/util/Util.js +0 -12
- package/dist/util/Util.js.map +0 -1
- package/dist/util/XMLUploadParser.d.ts +0 -22
- package/dist/util/XMLUploadParser.js +0 -67
- package/dist/util/XMLUploadParser.js.map +0 -1
- package/src/IncludePaths.ts +0 -122
- package/src/Keys.ts +0 -274
- package/src/TypeScript.ts +0 -65
- package/src/XML.ts +0 -98
- package/src/plugins/Context.ts +0 -239
- package/src/plugins/Plugin.ts +0 -278
- package/src/plugins/behaviors/Arranger.ts +0 -42
- package/src/plugins/behaviors/Composer.ts +0 -125
- package/src/plugins/behaviors/Diagnostics.ts +0 -12
- package/src/plugins/behaviors/Generator.ts +0 -31
- package/src/plugins/behaviors/OwnedTables.ts +0 -5
- package/src/plugins/behaviors/PostProcessor.ts +0 -6
- package/src/plugins/behaviors/Serializer.ts +0 -40
- package/src/plugins/behaviors/Transformer.ts +0 -32
- package/src/plugins/behaviors/extractors/Data.ts +0 -332
- package/src/plugins/behaviors/extractors/Extractors.ts +0 -73
- package/src/plugins/behaviors/extractors/index.ts +0 -2
- package/src/plugins/behaviors/index.ts +0 -9
- package/src/plugins/util/CallExpression.ts +0 -110
- package/src/plugins/util/CodeTransformation.ts +0 -731
- package/src/plugins/util/ObjectLiteral.ts +0 -37
- package/src/plugins/util/index.ts +0 -3
- package/src/util/Debug.ts +0 -24
- package/src/util/Directive.ts +0 -123
- package/src/util/RuntimeTableSchema.ts +0 -44
- package/src/util/Util.ts +0 -7
- package/src/util/XMLUploadParser.ts +0 -90
- /package/dist/util/{Scope.d.ts → is-sn-scope.d.ts} +0 -0
- /package/src/util/{Scope.ts → is-sn-scope.ts} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { TimeDuration } from '@servicenow/sdk/core'
|
|
2
|
+
|
|
3
|
+
function prefixZeroIfNeeded(n: number) {
|
|
4
|
+
return n < 10 ? `0${n}` : `${n}`
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function formatDateToPlatformFormat(date: Date | undefined): string {
|
|
8
|
+
if (date === undefined) {
|
|
9
|
+
return '1970-01-01 00:00:00'
|
|
10
|
+
}
|
|
11
|
+
return `${date.getUTCFullYear()}-${prefixZeroIfNeeded(date.getUTCMonth() + 1)}-${prefixZeroIfNeeded(date.getUTCDate())} ${prefixZeroIfNeeded(date.getUTCHours())}:${prefixZeroIfNeeded(date.getUTCMinutes())}:${prefixZeroIfNeeded(date.getUTCSeconds())}`
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseGlideDuration(dateTimeStr: string | undefined): TimeDuration | undefined {
|
|
15
|
+
if (!dateTimeStr) {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const components = parseDateTime(dateTimeStr)
|
|
20
|
+
if (!components) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Create Date objects for both the input time and epoch
|
|
25
|
+
const inputDate = new Date(
|
|
26
|
+
components.year,
|
|
27
|
+
components.month - 1,
|
|
28
|
+
components.day,
|
|
29
|
+
components.hours,
|
|
30
|
+
components.minutes,
|
|
31
|
+
components.seconds
|
|
32
|
+
)
|
|
33
|
+
const epochDate = new Date(1970, 0, 1, 0, 0, 0)
|
|
34
|
+
|
|
35
|
+
let diffMs = inputDate.getTime() - epochDate.getTime()
|
|
36
|
+
|
|
37
|
+
const duration: TimeDuration = {}
|
|
38
|
+
|
|
39
|
+
// Calculate days
|
|
40
|
+
const days = Math.floor(diffMs / (1000 * 60 * 60 * 24))
|
|
41
|
+
if (days > 0) {
|
|
42
|
+
duration.days = days
|
|
43
|
+
diffMs -= days * 1000 * 60 * 60 * 24
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Calculate hours
|
|
47
|
+
const hours = Math.floor(diffMs / (1000 * 60 * 60))
|
|
48
|
+
if (hours > 0) {
|
|
49
|
+
duration.hours = hours
|
|
50
|
+
diffMs -= hours * 1000 * 60 * 60
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Calculate minutes
|
|
54
|
+
const minutes = Math.floor(diffMs / (1000 * 60))
|
|
55
|
+
if (minutes > 0) {
|
|
56
|
+
duration.minutes = minutes
|
|
57
|
+
diffMs -= minutes * 1000 * 60
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Calculate seconds
|
|
61
|
+
const seconds = Math.floor(diffMs / 1000)
|
|
62
|
+
if (seconds > 0) {
|
|
63
|
+
duration.seconds = seconds
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return duration
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function parseDateTime(dateTimeStr: string | undefined) {
|
|
70
|
+
if (!dateTimeStr) {
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
const regex = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/
|
|
74
|
+
const match = dateTimeStr.match(regex)
|
|
75
|
+
|
|
76
|
+
if (match) {
|
|
77
|
+
const [, year, month, day, hours, minutes, seconds] = match
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
year: Number(year),
|
|
81
|
+
month: Number(month),
|
|
82
|
+
day: Number(day),
|
|
83
|
+
hours: Number(hours),
|
|
84
|
+
minutes: Number(minutes),
|
|
85
|
+
seconds: Number(seconds),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return undefined
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function durationFieldToXML(duration: TimeDuration): Date {
|
|
92
|
+
const durationInMs = toMilliseconds(
|
|
93
|
+
duration['days'] !== undefined ? duration['days'] : 0,
|
|
94
|
+
duration['hours'] !== undefined ? duration['hours'] : 0,
|
|
95
|
+
duration['minutes'] !== undefined ? duration['minutes'] : 0,
|
|
96
|
+
duration['seconds'] !== undefined ? duration['seconds'] : 0
|
|
97
|
+
)
|
|
98
|
+
return new Date(durationInMs)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function toMilliseconds(days: number, hours: number, minutes: number, seconds: number): number {
|
|
102
|
+
const msInDay = 24 * 60 * 60 * 1000
|
|
103
|
+
const msInHour = 60 * 60 * 1000
|
|
104
|
+
const msInMinute = 60 * 1000
|
|
105
|
+
const msInSecond = 1000
|
|
106
|
+
|
|
107
|
+
return days * msInDay + hours * msInHour + minutes * msInMinute + seconds * msInSecond
|
|
108
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin, Shape, File, ts } from '..'
|
|
2
|
+
|
|
3
|
+
export class PluginUsageTracker {
|
|
4
|
+
private readonly sourcesConvertedToRecords: Set<ts.Node | Shape | File> = new Set()
|
|
5
|
+
private readonly recordCountPerPlugin: Map<Plugin, number> = new Map()
|
|
6
|
+
|
|
7
|
+
clearPluginToRecordUsage() {
|
|
8
|
+
this.sourcesConvertedToRecords.clear()
|
|
9
|
+
this.recordCountPerPlugin.clear()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
addPluginToRecordUsage(plugin: Plugin, source: ts.Node | Shape | File, count: number) {
|
|
13
|
+
if (!this.sourcesConvertedToRecords.has(source)) {
|
|
14
|
+
this.sourcesConvertedToRecords.add(source)
|
|
15
|
+
const existingCount = this.recordCountPerPlugin.get(plugin) ?? 0
|
|
16
|
+
this.recordCountPerPlugin.set(plugin, existingCount + count)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getRecordCountPerPlugin() {
|
|
21
|
+
return [...this.recordCountPerPlugin.entries()].map(([plugin, count]) => ({
|
|
22
|
+
plugin: plugin.getName().replace(/Plugin$/, ''), //Report just the names 'ACL', 'Record', etc for existing metrics compatibility
|
|
23
|
+
count,
|
|
24
|
+
}))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Most of this is directly from prettiers config loading
|
|
3
|
+
* https://github.com/prettier/prettier/blob/main/src/config/prettier-config/loaders.js
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { pathToFileURL } from 'url'
|
|
7
|
+
import { JSON5, FileSystem, path } from '..'
|
|
8
|
+
import type { Options } from 'prettier'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Resolves the closest prettier config file from the given filepath.
|
|
12
|
+
* @param filepath Path to start the search from
|
|
13
|
+
* @param fs FileSystem
|
|
14
|
+
* @returns The resolved config Options or undefined if not found
|
|
15
|
+
*/
|
|
16
|
+
export async function resolveConfig(
|
|
17
|
+
filepath: string,
|
|
18
|
+
fs: FileSystem,
|
|
19
|
+
resolverCache: Map<string, Options | null>
|
|
20
|
+
): Promise<Options | null> {
|
|
21
|
+
const stopDir = findStopDir(path.dirname(filepath), fs)
|
|
22
|
+
const cached = resolverCache.get(stopDir)
|
|
23
|
+
if (cached) {
|
|
24
|
+
return cached
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const config = await findClosest(CONFIG_FILE_NAMES, path.dirname(filepath), stopDir, fs)
|
|
28
|
+
|
|
29
|
+
resolverCache.set(stopDir, config)
|
|
30
|
+
|
|
31
|
+
return config
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Recursively finds the closest directory that contains a .git or .hg directory, which indicates the root of the project.
|
|
35
|
+
function findStopDir(currentPath: string, fs: FileSystem): string {
|
|
36
|
+
if (FileSystem.existsSync(fs, currentPath)) {
|
|
37
|
+
const dirFiles = fs.readdirSync(currentPath, { withFileTypes: true })
|
|
38
|
+
if (dirFiles.some((d) => d.isDirectory() && (d.name === '.git' || d.name === '.hg'))) {
|
|
39
|
+
// If we found a .git or .hg directory, we stop searching which indicates we are at the root of the project
|
|
40
|
+
return currentPath
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const parent = path.dirname(currentPath)
|
|
45
|
+
if (parent === currentPath) {
|
|
46
|
+
return currentPath
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return findStopDir(parent, fs)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function loadConfig(file: string, fs: FileSystem): Promise<Options | null> {
|
|
53
|
+
const ext = path.extname(file)
|
|
54
|
+
switch (ext) {
|
|
55
|
+
case '.json5':
|
|
56
|
+
case '.prettierrc':
|
|
57
|
+
return loadJson5(file, fs)
|
|
58
|
+
case '.json':
|
|
59
|
+
return readJson(file, fs)
|
|
60
|
+
case '.js':
|
|
61
|
+
case '.mjs':
|
|
62
|
+
case '.cjs':
|
|
63
|
+
return importModuleDefault(file)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function findClosest(
|
|
70
|
+
fileNames: string[],
|
|
71
|
+
currentPath: string,
|
|
72
|
+
stopDir: string,
|
|
73
|
+
fs: FileSystem
|
|
74
|
+
): Promise<Options | null> {
|
|
75
|
+
if (FileSystem.existsSync(fs, currentPath)) {
|
|
76
|
+
if (FileSystem.existsSync(fs, path.join(currentPath, 'package.json'))) {
|
|
77
|
+
const pkJsonConfig = await loadConfigFromPackageJson(path.join(currentPath, 'package.json'), fs)
|
|
78
|
+
if (pkJsonConfig) {
|
|
79
|
+
return pkJsonConfig
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const dirFiles = fs.readdirSync(currentPath, { withFileTypes: true })
|
|
84
|
+
for (const items of dirFiles.filter((d) => d.isFile())) {
|
|
85
|
+
if (fileNames.includes(items.name)) {
|
|
86
|
+
return loadConfig(path.join(currentPath, items.name), fs)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const parent = path.dirname(currentPath)
|
|
92
|
+
if (parent === currentPath || currentPath === stopDir) {
|
|
93
|
+
return null
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return findClosest(fileNames, parent, stopDir, fs)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const CONFIG_FILE_NAMES = [
|
|
100
|
+
'.prettierrc',
|
|
101
|
+
'.prettierrc.json',
|
|
102
|
+
'.prettierrc.json5',
|
|
103
|
+
'.prettierrc.js',
|
|
104
|
+
'.prettierrc.mjs',
|
|
105
|
+
'.prettierrc.cjs',
|
|
106
|
+
'prettier.config.js',
|
|
107
|
+
'prettier.config.mjs',
|
|
108
|
+
'prettier.config.cjs',
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
function readJson(file: string, fs: FileSystem) {
|
|
112
|
+
const content = fs.readFileSync(file, { encoding: 'utf-8' })
|
|
113
|
+
return JSON.parse(content)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function importModuleDefault(file: string) {
|
|
117
|
+
const { href } = pathToFileURL(file)
|
|
118
|
+
const module = await import(href)
|
|
119
|
+
return module.default
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function loadConfigFromPackageJson(file: string, fs: FileSystem) {
|
|
123
|
+
const { prettier } = readJson(file, fs)
|
|
124
|
+
return prettier
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function loadJson5(file: string, fs: FileSystem) {
|
|
128
|
+
const content = fs.readFileSync(file, { encoding: 'utf-8' })
|
|
129
|
+
return JSON5.parse(content)
|
|
130
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface Telemetry {
|
|
2
|
+
sendEvent(eventData: TelemetryEvent | TelemetryEvent[]): Promise<void>
|
|
3
|
+
error(event: string, error: unknown, data?: TelemetryEventData): Promise<void>
|
|
4
|
+
startTimerEvent(name: TelemetryEvent['name']): TimerMetric
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface TimerMetric {
|
|
8
|
+
end(eventData?: Pick<TelemetryEvent, 'appInfo' | 'data'>): TelemetryEvent
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TelemetryEventData = Record<string, unknown>
|
|
12
|
+
|
|
13
|
+
export type TelemetryEvent = { name: string; appInfo?: { scopeId?: string }; data?: TelemetryEventData }
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This is a no-op telemetry implementation that does nothing.
|
|
17
|
+
*/
|
|
18
|
+
export class NoOpTelemetry implements Telemetry {
|
|
19
|
+
startTimerEvent(): TimerMetric {
|
|
20
|
+
return {
|
|
21
|
+
end: () => ({ name: '', data: {} }),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
start = () => Promise.resolve()
|
|
25
|
+
sendEvent = () => Promise.resolve()
|
|
26
|
+
error = () => Promise.resolve()
|
|
27
|
+
}
|