-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-npm-build.js
More file actions
53 lines (42 loc) · 1.46 KB
/
test-npm-build.js
File metadata and controls
53 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { execSync } from 'child_process';
import fs from 'fs';
import path from 'path';
// Step 1: Build the package
console.log('Building package...');
execSync('npm run build', { stdio: 'inherit' });
// Step 2: Pack the package
console.log('Packing package...');
const packOutput = execSync('npm pack').toString().trim();
const tarball = packOutput.split('\n').pop();
console.log(`Tarball created: ${tarball}`);
// Step 3: Create a temp test project
const tempDir = path.join(process.cwd(), 'npm-test-temp');
if (fs.existsSync(tempDir)) fs.rmSync(tempDir, { recursive: true, force: true });
fs.mkdirSync(tempDir);
fs.writeFileSync(
path.join(tempDir, 'package.json'),
JSON.stringify(
{
name: 'npm-test-temp',
version: '1.0.0',
type: 'module'
},
null,
2
)
);
// Step 4: Install the tarball
console.log('Installing tarball in temp project...');
execSync(`npm install ../${tarball}`, { cwd: tempDir, stdio: 'inherit' });
// Step 5: Create and run import test
const testCode = `
import { parseVisioFile } from 'vsdx-js';
console.log('Testing imports:');
console.log('- parseVisioFile:', typeof parseVisioFile === 'function' ? 'OK' : 'FAIL');
console.log('All imports successful!');
`;
fs.writeFileSync(path.join(tempDir, 'test.mjs'), testCode);
console.log('Running import test...');
execSync('node test.mjs', { cwd: tempDir, stdio: 'inherit' });
console.log('Test complete. Cleaning up...');
fs.rmSync(tempDir, { recursive: true, force: true });