@bobfrankston/npmglobalize 1.0.101 → 1.0.102

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.
Files changed (2) hide show
  1. package/lib.js +35 -4
  2. package/package.json +1 -1
package/lib.js CHANGED
@@ -1301,6 +1301,37 @@ const RECOMMENDED_GITIGNORE = [
1301
1301
  '*.ldf',
1302
1302
  '*.ndf'
1303
1303
  ];
1304
+ /** Extensions only recommended for .gitignore when matching files exist in the project */
1305
+ const PRESENCE_ONLY_EXTENSIONS = new Set(['.mdf', '.ldf', '.ndf']);
1306
+ /** Check if any files with the given extension exist in dir (skips node_modules, .git, prev) */
1307
+ function hasFilesWithExtension(dir, ext) {
1308
+ const skip = new Set(['node_modules', '.git', 'prev']);
1309
+ function check(d) {
1310
+ try {
1311
+ for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
1312
+ if (skip.has(entry.name))
1313
+ continue;
1314
+ if (entry.isFile() && entry.name.endsWith(ext))
1315
+ return true;
1316
+ if (entry.isDirectory() && check(path.join(d, entry.name)))
1317
+ return true;
1318
+ }
1319
+ }
1320
+ catch { }
1321
+ return false;
1322
+ }
1323
+ return check(dir);
1324
+ }
1325
+ /** Filter RECOMMENDED_GITIGNORE to skip presence-only patterns when no matching files exist */
1326
+ function getApplicableGitignorePatterns(cwd) {
1327
+ return RECOMMENDED_GITIGNORE.filter(pattern => {
1328
+ const extMatch = pattern.match(/^\*(\.\w+)$/);
1329
+ if (extMatch && PRESENCE_ONLY_EXTENSIONS.has(extMatch[1])) {
1330
+ return hasFilesWithExtension(cwd, extMatch[1]);
1331
+ }
1332
+ return true;
1333
+ });
1334
+ }
1304
1335
  /** Recommended .npmignore patterns */
1305
1336
  const RECOMMENDED_NPMIGNORE = [
1306
1337
  '.git/',
@@ -1341,7 +1372,7 @@ function checkIgnoreFiles(cwd, options) {
1341
1372
  if (fs.existsSync(gitignorePath)) {
1342
1373
  const content = fs.readFileSync(gitignorePath, 'utf-8');
1343
1374
  const lines = content.split('\n').map(l => l.trim());
1344
- for (const pattern of RECOMMENDED_GITIGNORE) {
1375
+ for (const pattern of getApplicableGitignorePatterns(cwd)) {
1345
1376
  if (!lines.some(line => line === pattern || line === pattern.replace('/', ''))) {
1346
1377
  changes.push(` .gitignore missing: ${pattern}`);
1347
1378
  }
@@ -1395,7 +1426,7 @@ function conformIgnoreFiles(cwd) {
1395
1426
  const content = fs.readFileSync(gitignorePath, 'utf-8');
1396
1427
  const lines = new Set(content.split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#')));
1397
1428
  let updated = false;
1398
- for (const pattern of RECOMMENDED_GITIGNORE) {
1429
+ for (const pattern of getApplicableGitignorePatterns(cwd)) {
1399
1430
  const normalized = pattern.replace('/', '');
1400
1431
  if (!lines.has(pattern) && !lines.has(normalized)) {
1401
1432
  lines.add(pattern);
@@ -1468,9 +1499,9 @@ function ensureGitignore(cwd) {
1468
1499
  // Update .gitignore if needed
1469
1500
  if (needsUpdate) {
1470
1501
  if (!content || content.trim() === '') {
1471
- // Create new .gitignore from RECOMMENDED_GITIGNORE plus extras
1502
+ // Create new .gitignore from applicable patterns plus extras
1472
1503
  const extras = ['*certs*/', 'configuration.json', 'cruft/', 'prev/', 'tests/'];
1473
- content = [...RECOMMENDED_GITIGNORE, ...extras].join('\n') + '\n';
1504
+ content = [...getApplicableGitignorePatterns(cwd), ...extras].join('\n') + '\n';
1474
1505
  }
1475
1506
  else {
1476
1507
  // Add node_modules to existing .gitignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.101",
3
+ "version": "1.0.102",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",