Skip to content

Commit 27e5875

Browse files
đź‘· Remove version field from package.json in flagging and performances packages (#3928)
1 parent b96f9ab commit 27e5875

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

‎packages/flagging/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "@datadog/browser-flagging",
3-
"version": "6.22.0",
43
"license": "Apache-2.0",
54
"private": true,
65
"main": "cjs/entries/main.js",

‎performances/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"private": true,
33
"name": "performances",
4-
"version": "6.22.0",
54
"scripts": {
65
"start": "ts-node ./src/main.ts"
76
},

‎scripts/check-packages.ts‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
3-
import { globSync } from 'glob'
3+
import { globSync } from 'node:fs'
44
import { minimatch } from 'minimatch'
5-
import { printLog, printError, runMain } from './lib/executionUtils.ts'
5+
import { printLog, printError, runMain, printWarning } from './lib/executionUtils.ts'
66
import { command } from './lib/command.ts'
77

88
interface PackageFile {
@@ -28,9 +28,18 @@ runMain(() => {
2828
})
2929

3030
function checkPackage(packagePath: string): boolean {
31+
const packageJson = getPackageJson(packagePath)
32+
33+
if (packageJson?.private) {
34+
printWarning(`Skipping private package ${packageJson.name}`)
35+
return true
36+
}
37+
3138
printLog(`Checking ${packagePath}`)
39+
3240
const packageFiles = getPackageFiles(packagePath)
33-
return checkPackageJsonEntryPoints(packagePath, packageFiles) && checkNpmIgnore(packagePath, packageFiles)
41+
42+
return checkPackageJsonEntryPoints(packageJson, packageFiles) && checkNpmIgnore(packagePath, packageFiles)
3443
}
3544

3645
function getPackageFiles(packagePath: string): string[] {
@@ -44,19 +53,12 @@ function getPackageFiles(packagePath: string): string[] {
4453
return parsed[0].files.map((file) => file.path)
4554
}
4655

47-
function checkPackageJsonEntryPoints(packagePath: string, packageFiles: string[]): boolean {
48-
const filesFromPackageJsonEntryPoints = packageFiles
49-
.filter((file) => file.endsWith('package.json'))
50-
.flatMap((packageJsonPath) => {
51-
const content = JSON.parse(fs.readFileSync(path.join(packagePath, packageJsonPath), 'utf8'))
52-
return [content.main, content.module, content.types]
53-
.filter(Boolean)
54-
.map((entryPointPath: string) => path.join(path.dirname(packageJsonPath), entryPointPath))
55-
})
56+
function checkPackageJsonEntryPoints(packageJson: PackageJson, packageFiles: string[]): boolean {
57+
const filesFromPackageJsonEntryPoints = [packageJson.main, packageJson.module, packageJson.types].filter(Boolean)
5658

5759
for (const file of filesFromPackageJsonEntryPoints) {
5860
if (!packageFiles.includes(file)) {
59-
printError(`File ${file} used as an entry point in ${packagePath} is missing from the package`)
61+
printError(`File ${file} used as an entry point in ${packageJson.name} is missing from the package`)
6062
return false
6163
}
6264
}
@@ -94,3 +96,17 @@ function checkNpmIgnore(packagePath: string, packageFiles: string[]): boolean {
9496

9597
return true
9698
}
99+
100+
function getPackageJson(packagePath: string) {
101+
return globSync(path.join(packagePath, 'package.json')).map(
102+
(packageJsonFile) => JSON.parse(fs.readFileSync(packageJsonFile, 'utf8')) as PackageJson
103+
)[0]
104+
}
105+
106+
interface PackageJson {
107+
name: string
108+
private?: boolean
109+
main: string
110+
module: string
111+
types: string
112+
}

‎scripts/lib/executionUtils.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export function printLog(...params: any[]): void {
3939
console.log(greenColor, ...params, resetColor)
4040
}
4141

42+
export function printWarning(...params: any[]): void {
43+
const yellowColor = '\x1b[33;1m'
44+
console.log(yellowColor, ...params, resetColor)
45+
}
46+
4247
export function formatSize(bytes: number | null, { includeSign = false } = {}): string {
4348
if (bytes === null) {
4449
return 'N/A'

0 commit comments

Comments
 (0)