Skip to content

Commit

Permalink
feat: BREAKING CHANGE: Remove ignored_files from the config
Browse files Browse the repository at this point in the history
We use the packages' own `.npmignore` or `.gitignore` instead
  • Loading branch information
bencergazda committed Sep 24, 2021
1 parent d3f87ed commit 1e6dadb
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ package.json
"modules_dir": "node_modules",
"install_args": "", // extra arguments for the internal npm/yarn/pnpm install command (example: "--legacy-peer-deps")
"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)
}
```
Expand Down
2 changes: 0 additions & 2 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ async function install() {
manager,
install_args,
types,
ignored_files,
ignored_packages,
} = await getConfig();

const { original_package_json, mocked_dependencies, packed_dependencies } = await prepare_dependencies({
types,
cwd,
temp_path,
ignored_files,
ignored_packages,
});

Expand Down
5 changes: 2 additions & 3 deletions bin/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ const { prepare_dependencies, watch_dependencies } = require('../src/project');
const { delete_tarball } = require('../src/dependency');

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();

const { mocked_dependencies, packed_dependencies } = await prepare_dependencies({
types,
cwd,
temp_path,
ignored_files,
ignored_packages,
});

Expand All @@ -23,7 +22,7 @@ async function watch() {
return null;
}

await watch_dependencies(packed_dependencies, { cwd, modules_path, ignored_files });
await watch_dependencies(packed_dependencies, { cwd, modules_path });

return packed_dependencies;
}
Expand Down
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async function config() {
manager: 'npm',
install_args: '',
types: ['dependencies', 'devDependencies'],
ignored_files: ['package.json', 'node_modules', '.DS_Store'],
ignored_packages: [],
};

Expand Down
3 changes: 1 addition & 2 deletions src/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ function filename_from_package_name(name, version) {
* @param local_dependency_name
* @param local_dependency_path
* @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,
Expand Down
17 changes: 6 additions & 11 deletions src/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ function get_local_dependencies(package_json_content, { types, ignored_packages
/**
* @param local_dependencies {object}
* @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);
const packed_dependencies = [];

Expand All @@ -115,7 +114,7 @@ async function get_mocked_dependencies(local_dependencies, { temp_path, ignored_
const type_object = local_dependencies[type];

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 });

mocked_dependencies[type][name] = tarball.tarball_path;

Expand All @@ -128,7 +127,7 @@ async function get_mocked_dependencies(local_dependencies, { temp_path, ignored_
return { mocked_dependencies, packed_dependencies };
}

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
const original_package_json = get_package_json({ cwd });

Expand All @@ -137,14 +136,13 @@ async function prepare_dependencies({ types, cwd, temp_path, ignored_files, igno
// Create the tarballs, and get the mocked dependency paths
const { mocked_dependencies, packed_dependencies } = await get_mocked_dependencies(local_dependencies, {
temp_path,
ignored_files,
});

// This contains all the required data to install the dependencies, or start the watcher
return { original_package_json, local_dependencies, mocked_dependencies, packed_dependencies };
}

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');
if (!Array.isArray(packed_dependencies)) {
throw new Error('No data received to install the dependencies.');
Expand Down Expand Up @@ -193,15 +191,13 @@ async function collect_dependencies_files_flat(globed_dependencies) {
* @param packed_dependencies {array}
* @param cwd {string}
* @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');
const globed_dependencies = await collect_dependencies_files(packed_dependencies, {
cwd,
modules_path,
ignored_files,
});

const all_dependencies_files = await collect_dependencies_files_flat(globed_dependencies);
Expand All @@ -218,12 +214,11 @@ async function copy_dependencies(packed_dependencies, { cwd, modules_path, ignor
}));
}

async function watch_dependencies(packed_dependencies, { cwd, modules_path, ignored_files }) {
async function watch_dependencies(packed_dependencies, { cwd, modules_path }) {
// console.log('watch_dependencies');
const globed_dependencies = await collect_dependencies_files(packed_dependencies, {
cwd,
modules_path,
ignored_files,
});

const files_to_watch = globed_dependencies.map(({ local_package_path }) => `${local_package_path}/.`);
Expand Down

0 comments on commit 1e6dadb

Please sign in to comment.