install-local-dependencies
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -18,3 +18,2 @@ #!/usr/bin/env node | ||
types, | ||
ignored_files, | ||
ignored_packages, | ||
@@ -27,3 +26,2 @@ } = await getConfig(); | ||
temp_path, | ||
ignored_files, | ||
ignored_packages, | ||
@@ -30,0 +28,0 @@ }); |
@@ -8,3 +8,3 @@ #!/usr/bin/env node | ||
async function watch() { | ||
const { cwd, temp_path, modules_path, manager, types, ignored_files, ignored_packages } = await getConfig(); | ||
const { cwd, temp_path, modules_path, manager, types, ignored_packages } = await getConfig(); | ||
@@ -15,3 +15,2 @@ const { mocked_dependencies, packed_dependencies } = await prepare_dependencies({ | ||
temp_path, | ||
ignored_files, | ||
ignored_packages, | ||
@@ -28,3 +27,3 @@ }); | ||
await watch_dependencies(packed_dependencies, { cwd, modules_path, ignored_files }); | ||
await watch_dependencies(packed_dependencies, { cwd, modules_path }); | ||
@@ -31,0 +30,0 @@ return packed_dependencies; |
@@ -5,2 +5,15 @@ # Changelog | ||
## [0.2.0](https://github.com/body-builder/install-local-dependencies/compare/v0.1.1...v0.2.0) (2021-09-24) | ||
### Features | ||
* BREAKING CHANGE: Remove `ignored_files` from the config ([1e6dadb](https://github.com/body-builder/install-local-dependencies/commit/1e6dadba54297bf327de918755a4f3c21fe4621b)) | ||
* Use `.npmignore` or `.gitignore` as ignore pattern ([d3f87ed](https://github.com/body-builder/install-local-dependencies/commit/d3f87ed17b9ffa4841ba7fd8b04a406f2202fb61)) | ||
### Bug Fixes | ||
* Windows backslash-issue in `get_target_path()` ([8cad12a](https://github.com/body-builder/install-local-dependencies/commit/8cad12a64f651880196582a58f7e9e9e01e26eae)) | ||
### [0.1.2](https://github.com/body-builder/install-local-dependencies/compare/v0.1.1...v0.1.2) (2021-08-26) | ||
@@ -7,0 +20,0 @@ |
{ | ||
"name": "install-local-dependencies", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Yet another local dependency installer", | ||
@@ -35,4 +35,4 @@ "homepage": "https://github.com/body-builder/install-local-dependencies#readme", | ||
"fs-extra": "^10.0.0", | ||
"globby": "^11.0.3", | ||
"lodash": "^4.17.21", | ||
"npm-packlist": "^3.0.0", | ||
"pify": "^5.0.0", | ||
@@ -39,0 +39,0 @@ "rimraf": "^3.0.2", |
@@ -53,3 +53,2 @@ # Install local dependencies | ||
"types": ["dependencies"], // dependency types you want to handle with `install-local-dependencies` (these packages will also get installed, but in the regular way) (defaults to ["dependencies", "devDependencies"]) | ||
"ignored_files": ["**/an_ignored_file.ext"], // files not to include to the installed package (defaults to ["package.json", "node_modules"]) | ||
"ignored_packages": [], // list of local packages you don't want to handle with `install-local-dependencies` (these packages will also get installed, but in the regular way) | ||
@@ -56,0 +55,0 @@ } |
@@ -21,3 +21,2 @@ const path = require('path'); | ||
types: ['dependencies', 'devDependencies'], | ||
ignored_files: ['package.json', 'node_modules', '.DS_Store'], | ||
ignored_packages: [], | ||
@@ -24,0 +23,0 @@ }; |
const path = require('path'); | ||
const globby = require('globby'); | ||
const packlist = require('npm-packlist'); | ||
const tar = require('tar'); | ||
const execSh = require('exec-sh').promise; | ||
const { validate_path, promisified } = require('./helpers') | ||
const { validate_path, promisified, default_ignore_rules } = require('./helpers') | ||
@@ -33,2 +33,49 @@ /** | ||
/** | ||
* Returns the Array of the ignore-rules based on the root `.npmignore` file, or if that doesn't exist, based on the root `.gitignore` file | ||
* @param relative_package_path | ||
* @returns {Promise<*[]|*>} | ||
*/ | ||
async function get_ignore_file_rules(relative_package_path) { | ||
const npmignorePath = path.resolve(relative_package_path, '.npmignore'); | ||
const gitignorePath = path.resolve(relative_package_path, '.gitignore'); | ||
let ignorefile; | ||
try { | ||
// try to read .npmignore | ||
ignorefile = await promisified.fs.readFile(npmignorePath, 'utf-8'); | ||
} catch (e) { | ||
// .npmignore not found, try to read .gitignore | ||
try { | ||
ignorefile = await promisified.fs.readFile(gitignorePath, 'utf-8'); | ||
} catch (e) { | ||
// No ignore file found | ||
return []; | ||
} | ||
} | ||
return ignorefile | ||
.split('\n') | ||
.filter(Boolean) // Empty lines | ||
.filter((line) => !line.trim().startsWith('#')); // Comments | ||
} | ||
/** | ||
* Returns the list of the | ||
* @param relative_package_path | ||
* @returns {Promise<*[]>} | ||
*/ | ||
async function get_ignore_rules(relative_package_path) { | ||
const local_ignore_rules = await get_ignore_file_rules(relative_package_path); | ||
const all_rules = [ | ||
'node_modules', // We don't manage `bundledDependencies` in watch mode! | ||
...default_ignore_rules, | ||
...local_ignore_rules, | ||
]; | ||
return all_rules.map((pattern) => path.join(relative_package_path, pattern)); | ||
} | ||
/** | ||
* Returns an NPM-style tarball filename (without extension) | ||
@@ -59,10 +106,8 @@ * @param name {string} | ||
* @param temp_path | ||
* @param ignored_files | ||
* @returns {Promise<string>} | ||
*/ | ||
async function create_tarball({ name: local_dependency_name, version: local_dependency_path }, { temp_path, ignored_files }) { | ||
async function create_tarball({ name: local_dependency_name, version: local_dependency_path }, { temp_path }) { | ||
// console.log('create_tarball', local_dependency_path); | ||
const { | ||
package_path, | ||
package_json_filename, | ||
package_json_content, | ||
@@ -76,9 +121,3 @@ } = await get_package_details(local_dependency_path); | ||
const local_package_files = await globby('**/*', { | ||
cwd: package_path, | ||
dot: true, | ||
onlyFiles: false, | ||
markDirectories: true, | ||
ignore: ignored_files, | ||
}); | ||
const local_package_files = await packlist({ path: package_path }); | ||
@@ -93,3 +132,3 @@ try { | ||
}, | ||
[package_json_filename, ...local_package_files], | ||
local_package_files, | ||
); | ||
@@ -151,2 +190,4 @@ } catch (e) { | ||
module.exports = { | ||
get_ignore_file_rules, | ||
get_ignore_rules, | ||
create_tarball, | ||
@@ -153,0 +194,0 @@ install_tarball, |
@@ -16,2 +16,30 @@ const path = require('path'); | ||
// https://github.com/npm/npm-packlist/blob/main/index.js#L37 | ||
const default_ignore_rules = [ | ||
'.npmignore', | ||
'.gitignore', | ||
'**/.git', | ||
'**/.svn', | ||
'**/.hg', | ||
'**/CVS', | ||
'**/.git/**', | ||
'**/.svn/**', | ||
'**/.hg/**', | ||
'**/CVS/**', | ||
'/.lock-wscript', | ||
'/.wafpickle-*', | ||
'/build/config.gypi', | ||
'npm-debug.log', | ||
'**/.npmrc', | ||
'.*.swp', | ||
'.DS_Store', | ||
'**/.DS_Store/**', | ||
'._*', | ||
'**/._*/**', | ||
'*.orig', | ||
'/package-lock.json', | ||
'/yarn.lock', | ||
'/archived-packages/**', | ||
]; | ||
// https://stackoverflow.com/a/41407246/3111787 | ||
@@ -160,2 +188,3 @@ // https://en.wikipedia.org/wiki/ANSI_escape_code#Colors | ||
definitely_posix, | ||
default_ignore_rules, | ||
promisified, | ||
@@ -162,0 +191,0 @@ console_colors, |
@@ -6,3 +6,3 @@ const path = require('path'); | ||
const { create_tarball } = require('./dependency'); | ||
const { create_tarball, get_ignore_rules } = require('./dependency'); | ||
const { | ||
@@ -107,6 +107,5 @@ remove_file_or_directory, | ||
* @param temp_path {string} | ||
* @param ignored_files {string[]} | ||
* @returns {Promise<{mocked_dependencies, created_tarballs: []}>} | ||
*/ | ||
async function get_mocked_dependencies(local_dependencies, { temp_path, ignored_files }) { | ||
async function get_mocked_dependencies(local_dependencies, { temp_path }) { | ||
const mocked_dependencies = _.cloneDeep(local_dependencies); | ||
@@ -120,3 +119,3 @@ const packed_dependencies = []; | ||
return await Promise.all(Object.entries(type_object).map(async ([name, version]) => { | ||
const tarball = await create_tarball({ name, version }, { temp_path, ignored_files }); | ||
const tarball = await create_tarball({ name, version }, { temp_path }); | ||
@@ -134,3 +133,3 @@ mocked_dependencies[type][name] = tarball.tarball_path; | ||
async function prepare_dependencies({ types, cwd, temp_path, ignored_files, ignored_packages }) { | ||
async function prepare_dependencies({ types, cwd, temp_path, ignored_packages }) { | ||
// Save original package.json content | ||
@@ -144,3 +143,2 @@ const original_package_json = get_package_json({ cwd }); | ||
temp_path, | ||
ignored_files, | ||
}); | ||
@@ -152,3 +150,3 @@ | ||
async function collect_dependencies_files(packed_dependencies, { cwd, modules_path, ignored_files }) { | ||
async function collect_dependencies_files(packed_dependencies, { cwd, modules_path }) { | ||
// console.log('collect_dependencies_files'); | ||
@@ -202,6 +200,5 @@ if (!Array.isArray(packed_dependencies)) { | ||
* @param modules_path {string} | ||
* @param ignored_files {string} | ||
* @returns {Promise<void>} | ||
*/ | ||
async function copy_dependencies(packed_dependencies, { cwd, modules_path, ignored_files }) { | ||
async function copy_dependencies(packed_dependencies, { cwd, modules_path }) { | ||
// console.log('copy_dependencies'); | ||
@@ -211,3 +208,2 @@ const globed_dependencies = await collect_dependencies_files(packed_dependencies, { | ||
modules_path, | ||
ignored_files, | ||
}); | ||
@@ -229,3 +225,3 @@ | ||
async function watch_dependencies(packed_dependencies, { cwd, modules_path, ignored_files }) { | ||
async function watch_dependencies(packed_dependencies, { cwd, modules_path }) { | ||
// console.log('watch_dependencies'); | ||
@@ -235,10 +231,9 @@ const globed_dependencies = await collect_dependencies_files(packed_dependencies, { | ||
modules_path, | ||
ignored_files, | ||
}); | ||
const files_to_watch = globed_dependencies.map(({ local_package_path }) => `${local_package_path}/.`); | ||
const ignore_glob = `{${ignored_files.map((rule) => `**/${rule}`).join(',')}}`; | ||
const ignore_glob = await Promise.all(globed_dependencies.map(({ local_package_path }) => get_ignore_rules(local_package_path))); | ||
const watcher = chokidar.watch(files_to_watch, { | ||
ignored: ignore_glob, | ||
ignored: `{${ignore_glob.join(',')}}`, | ||
}); | ||
@@ -245,0 +240,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29474
708
60
+ Addednpm-packlist@^3.0.0
+ Addedignore-walk@4.0.1(transitive)
+ Addednpm-bundled@1.1.2(transitive)
+ Addednpm-normalize-package-bin@1.0.1(transitive)
+ Addednpm-packlist@3.0.0(transitive)
- Removedglobby@^11.0.3
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removedarray-union@2.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.18.0(transitive)
- Removedglobby@11.1.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedslash@3.0.0(transitive)