Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/nw patch #2138

Merged
merged 22 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nativewind/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"main": "index.js",
"module": "index.js",
"types": "index.d.ts",
"version": "1.0.15-alpha.0",
"version": "1.0.16",
"react-native": "src/index",
"source": "src/index",
"scripts": {
Expand Down
60 changes: 27 additions & 33 deletions packages/nativewind/utils/scripts/post-install-script.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
const fs = require('fs');
const path = require('path');
var finder = require('./find-package-json');
const { spawnSync } = require('child_process');
const { exec } = require('child_process');
const findWorkspaceRoot = require('find-yarn-workspace-root');

const processPath = process.cwd();
const workspaceRoot = findWorkspaceRoot(processPath);
const f = finder(path.join(processPath, '..'));
const userDirectory = f.next().filename.replace('package.json', '');
const filename = f.next().filename;
const userDirectory = filename.replace('package.json', '');

function CopyDirectory(src, dest) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}

let entries = fs.readdirSync(src, { withFileTypes: true });
const entries = fs.readdirSync(src, { withFileTypes: true });

for (let entry of entries) {
let srcPath = path.join(src, entry.name);
let destPath = path.join(dest, entry.name);
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);

if (entry.isDirectory()) {
CopyDirectory(srcPath, destPath);
Expand All @@ -27,41 +29,33 @@ function CopyDirectory(src, dest) {
}
}

function main() {
CopyDirectory(
path.join(processPath, 'scripts', 'patches'),
path.join(userDirectory, 'patches')
);
function installPatch(cwd) {
// use npm if user is using npm or yarn if user is using yarn
try {
const packageManager = fs.existsSync(path.join(userDirectory, 'yarn.lock'))
? 'yarn'
: 'npm run';

spawnSync(packageManager, ['patch-package'], {
cwd: userDirectory,
stdio: 'inherit',
});
} catch (error) {}
const packageManager = fs.existsSync(path.join(cwd, 'yarn.lock'))
? 'yarn'
: 'npx';

const command = packageManager + ' patch-package';
exec(command, {
cwd: cwd,
stdio: 'inherit',
});
}

function main() {
if (workspaceRoot && workspaceRoot !== userDirectory) {
CopyDirectory(
path.join(processPath, 'scripts', 'patches'),
path.join(workspaceRoot, 'patches')
);

try {
const packageManager = fs.existsSync(
path.join(workspaceRoot, 'yarn.lock')
)
? 'yarn'
: 'npm run';

spawnSync(packageManager, ['patch-package'], {
cwd: workspaceRoot,
stdio: 'inherit',
});
} catch (error) {}
installPatch(workspaceRoot);
} else {
CopyDirectory(
path.join(processPath, 'scripts', 'patches'),
path.join(userDirectory, 'patches')
);
installPatch(userDirectory);
}
}

Expand Down
Loading