Skip to content

Commit 422f2ec

Browse files
authored
refactor(angular-query): build package using vite (#9517)
1 parent 74d8ce6 commit 422f2ec

File tree

4 files changed

+7
-129
lines changed

4 files changed

+7
-129
lines changed

knip.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
"packages/vue-query": {
2323
"ignore": ["**/__mocks__/**"],
2424
"ignoreDependencies": ["vue2", "vue2.7"]
25-
},
26-
"packages/angular-query-experimental": {
27-
"ignore": ["scripts/prepack.js", "scripts/prepare-package.js"]
2825
}
2926
}
3027
}

packages/angular-query-experimental/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@
4343
"test:lib": "vitest",
4444
"test:lib:dev": "pnpm run test:lib --watch",
4545
"test:build": "publint --strict && attw --pack",
46-
"build": "pnpm build:tsup",
47-
"build:tsup": "tsup --tsconfig tsconfig.prod.json"
46+
"build": "vite build",
47+
"prepack": "node scripts/prepack.js"
4848
},
4949
"type": "module",
50-
"types": "build/index.d.ts",
51-
"module": "build/index.mjs",
50+
"types": "dist/index.d.ts",
51+
"module": "dist/index.mjs",
5252
"exports": {
5353
".": {
5454
"@tanstack/custom-condition": "./src/index.ts",
55-
"types": "./build/index.d.ts",
56-
"default": "./build/index.mjs"
55+
"types": "./dist/index.d.ts",
56+
"default": "./dist/index.mjs"
5757
},
5858
"./package.json": "./package.json"
5959
},
6060
"sideEffects": false,
6161
"files": [
62-
"build",
62+
"dist",
6363
"src",
6464
"!src/__tests__"
6565
],
Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1 @@
1-
import fs from 'node:fs'
2-
import path from 'node:path'
3-
4-
// Currently unused as life-cycle scripts do not run on CI
5-
61
console.log('Running prepack script')
7-
8-
/**
9-
* Files to copy to the dist directory
10-
* @type {string[]}
11-
*/
12-
const FILES_TO_COPY = ['README.md']
13-
14-
/**
15-
* Fields to remove from the package.json copy
16-
* @type {string[]}
17-
*/
18-
const FIELDS_TO_REMOVE = [
19-
'devDependencies',
20-
'files',
21-
'publishConfig',
22-
'scripts',
23-
]
24-
25-
/**
26-
* Replaces 'dist/' or './dist/' prefix from a file path with './'
27-
* @param {string} filePath - The file path to process
28-
* @returns {string} The path without dist prefix
29-
*/
30-
function removeDist(filePath) {
31-
return filePath.replace(/^(\.\/)?dist\//, './')
32-
}
33-
34-
/**
35-
* Recursively processes exports object to remove dist prefixes
36-
* @param {Record<string, any>} exports - The exports object to process
37-
* @returns {Record<string, any>} The processed exports object
38-
*/
39-
function processExports(exports) {
40-
return Object.fromEntries(
41-
Object.entries(exports).map(([key, value]) => [
42-
key,
43-
typeof value === 'string'
44-
? removeDist(value)
45-
: typeof value === 'object' && value !== null
46-
? processExports(value)
47-
: value,
48-
]),
49-
)
50-
}
51-
52-
console.log('Copying modified package.json')
53-
54-
/** @type {Record<string, any>} */
55-
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
56-
57-
const distPackageJson = { ...packageJson }
58-
59-
if (distPackageJson.types) {
60-
distPackageJson.types = removeDist(distPackageJson.types)
61-
}
62-
63-
if (distPackageJson.module) {
64-
distPackageJson.module = removeDist(distPackageJson.module)
65-
}
66-
67-
if (distPackageJson.exports) {
68-
distPackageJson.exports = processExports(distPackageJson.exports)
69-
}
70-
71-
for (const field of FIELDS_TO_REMOVE) {
72-
delete distPackageJson[field]
73-
}
74-
75-
if (!fs.existsSync('dist')) {
76-
fs.mkdirSync('dist', { recursive: true })
77-
}
78-
79-
fs.writeFileSync(
80-
path.join('dist', 'package.json'),
81-
JSON.stringify(distPackageJson, null, 2),
82-
)
83-
84-
console.log('Copying other files')
85-
for (const fileName of FILES_TO_COPY) {
86-
if (fs.existsSync(fileName)) {
87-
fs.copyFileSync(fileName, path.join('dist', fileName))
88-
console.log(`${fileName}`)
89-
} else {
90-
console.log(`${fileName} not found, skipping`)
91-
}
92-
}
93-
94-
console.log('prepack complete')

packages/angular-query-experimental/scripts/prepare-package.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)