Skip to content

Commit

Permalink
refact(): removed a lot of logic related to copy packages folder rsyn…
Browse files Browse the repository at this point in the history
…c is now gone and we are left with only npm resolutions
  • Loading branch information
Stradivario committed Mar 6, 2023
1 parent 72edadb commit 99bae53
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 233 deletions.
49 changes: 17 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,26 @@ If the binaries don't work in `mac` or `windows` please install it via `npm` glo

#### Usage

Bootstrapping the packages
It will run `npm install` inside the current working directory
This will install local packages referenced inside `fireDependencies`
It means that `node_modules` folder will be already populated with appropriate packages after `npm install`

```bash
firelink --bootstrap --no-runner
```

Deploying as usual

```bash
firelink deploy
```

The same as `firebase deploy` the only differance is that it will COPY monorepos replace package.json > dependencies with appropriate local file structure and then will revert changes after `firebase` script exit
You can also use one liner replacement for `npm install` and `firebase deploy`

```bash
firelink deploy --bootstrap
```

#### Leave changes to package.json after command execution exited

Expand Down Expand Up @@ -133,50 +148,20 @@ Revert the changes made inside `package.json`
firelink --no-runner --revert-changes
```

#### Native Nodejs Copy instead of `rsync`

This argument is introduced due to recent issue that has being made https://github.com/rxdi/firelink/issues/55
It appears that in the newest nodejs 16 docker image rsync package is missing

There is a way to specify which runner firelink will use
when specify `--use-native-copy` it will default to nodejs implementation of recursive copy the files
By default in windows environment this is the main method used to copy files since `rsync` is missing in windows

```
firelink --use-native-copy
```

# Configuration

Default runner is command `firebase` but you can change it for example to `gcloud` or `serverless` by defining `fireConfig` inside `package.json`

```json
{
"fireConfig": {
"runner": "firebase",
"outFolderName": ".packages",
"outFolderLocation": ".",
"excludes": ["node_modules"],
"useNativeCopy": true
"runner": "firebase"
}
}
```

`excludes` property can exclude some folders or files from being copied it accepts `Array` from `string`

For example we may want to install dependencies of the packages when deploying using local npm path,
so we want to not waste time duplicating node modules

Equivalent of excludes inside package.json `.fireignore` can be specified as a file inside a directory where the command `firelink` will be executed. `.fireignore` behaviour is the same as `.gitignore`

If you do not wish to use `.fireignore` file name the name can be specified from `fireConfig.excludesFileName`

You can pass `--runner dir` argument to the command which will override the default runner `firebase`

By default packages will be saved in `.packages` folder and `current` directory will be used
U can change that by specifiyng properties `outFolderName` and `outFolderLocation` inside `fireConfig`
Check `example` folder inside this repository

You can put even `dir` command

```json
Expand Down
2 changes: 1 addition & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"@test/dependency": "./packages/dependency"
},
"fireConfig": {
"runner": "npm",
"outFolderName": ".packages",
"outFolderLocation": ".",
"excludes": [
"node_modules"
],
"useNativeCopy": true
"runner": "firebase"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"ts-jest": "29.0.3",
"typescript": "^4.8.4"
}
}
}
24 changes: 12 additions & 12 deletions src/create-virtual-symlink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createVirtualSymlink } from './create-virtual-symlink';
import { PackageJson } from './injection-tokens';

const mockBuildPackages = jest.fn();
const mockCopyPackages = jest.fn();
// const mockCopyPackages = jest.fn();
const mockExitHandler = jest.fn();
const mockModifyJson = jest.fn();
const mockRevertJson = jest.fn();
Expand All @@ -11,15 +11,15 @@ const mockRunCommand = jest.fn();
jest.mock('./helpers/build-packages', () => ({
buildPackages: async (...args: unknown[]) => mockBuildPackages(...args),
}));
jest.mock('./helpers/copy-packages', () => ({
copyPackages:
(...args: unknown[]) =>
() =>
() =>
() =>
() =>
mockCopyPackages(...args),
}));
// jest.mock('./helpers/copy-packages', () => ({
// copyPackages:
// (...args: unknown[]) =>
// () =>
// () =>
// () =>
// () =>
// mockCopyPackages(...args),
// }));
jest.mock('./helpers/exit-handler', () => ({
exitHandler: (...args: unknown[]) => mockExitHandler(...args),
}));
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('createVirtualSymlink', () => {
it('should update dependencies if fireDependencies are present in original package.json', async () => {
mockRunCommand.mockImplementationOnce(() => Promise.resolve(true));
await createVirtualSymlink(fakePackageJson, outFolder, outFolderName);
expect(mockCopyPackages).toHaveBeenCalledTimes(1);
// expect(mockCopyPackages).toHaveBeenCalledTimes(1);
expect(mockModifyJson).toHaveBeenCalledTimes(1);
expect(mockRunCommand).toHaveBeenCalledTimes(1);
expect(mockExitHandler).toHaveBeenCalledWith(fakePackageJson, true);
Expand All @@ -85,7 +85,7 @@ describe('createVirtualSymlink', () => {
process.argv.push('--buildCommand');
mockRunCommand.mockImplementationOnce(() => Promise.resolve(true));
await createVirtualSymlink(fakePackageJson, outFolder, outFolderName);
expect(mockCopyPackages).toHaveBeenCalledTimes(1);
// expect(mockCopyPackages).toHaveBeenCalledTimes(1);
expect(mockBuildPackages).toHaveBeenCalledTimes(1);
expect(mockModifyJson).toHaveBeenCalledTimes(1);
expect(mockRunCommand).toHaveBeenCalledTimes(1);
Expand Down
17 changes: 5 additions & 12 deletions src/create-virtual-symlink.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { includes, nextOrDefault } from './helpers/args-extractors';
import { buildPackages } from './helpers/build-packages';
import { copyPackages } from './helpers/copy-packages';
import { exitHandler } from './helpers/exit-handler';
import { modifyJson } from './helpers/modify-json';
import { readExcludes } from './helpers/read-excludes';
import { revertJson } from './helpers/revert-json';
import { runCommand } from './helpers/run-command';
import { Worker } from './helpers/worker';
import {
DEFAULT_RUNNER,
FireLinkConfig,
Expand All @@ -27,13 +26,6 @@ export async function createVirtualSymlink(
packageJson.fireConfig.runner ||
DEFAULT_RUNNER;

const excludes = [
...(packageJson.fireConfig.excludes || []),
...(await readExcludes(
packageJson.fireConfig.excludesFileName || '.fireignore',
)),
];

if (includes(Tasks.REVERT)) {
return await revertJson(
WorkingFiles.PACKAGE_JSON,
Expand All @@ -49,9 +41,7 @@ export async function createVirtualSymlink(
dep,
folder: linkedDepndencies[dep],
}));
await copyPackages(dependencies)(outFolder)(outFolderName)(excludes)(
includes(Tasks.USE_NATIVE_COPY) || packageJson.fireConfig.useNativeCopy,
);

if (includes(Tasks.BUILD)) {
try {
await buildPackages(outFolder, outFolderName);
Expand All @@ -75,6 +65,9 @@ export async function createVirtualSymlink(
}

try {
if (includes(Tasks.BOOTSTRAP)) {
await Worker({ command: 'npm', args: ['install'] });
}
if (!includes(Tasks.NO_RUNNER)) {
await runCommand(runner, process.argv);
}
Expand Down
13 changes: 5 additions & 8 deletions src/helpers/build-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ export async function buildPackages(outFolder: string, outFolderName: string) {
(
await promisify(readdir)(join(outFolder, outFolderName))
).map(async (dir) => {
await Worker(
{
command: 'npx',
args: (nextOrDefault(Tasks.BUILD, 'tsc') as string).split(' '),
cwd: join(outFolder, outFolderName, dir),
},
false,
);
await Worker({
command: 'npx',
args: (nextOrDefault(Tasks.BUILD, 'tsc') as string).split(' '),
cwd: join(outFolder, outFolderName, dir),
});
}),
);
}
75 changes: 0 additions & 75 deletions src/helpers/copy-packages.ts

This file was deleted.

57 changes: 0 additions & 57 deletions src/helpers/copy-recursive.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/helpers/read-excludes.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/helpers/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ export async function runCommand(
runner,
...args
.slice(2)
.filter(
(a) =>
a !== Tasks.LEAVE_CHANGES &&
a !== Tasks.REVERT &&
a !== Tasks.BUILD,
),
.filter((a) => !Object.values(Tasks).includes(a as never)),
],
});
}
Loading

0 comments on commit 99bae53

Please sign in to comment.