Skip to content

Commit

Permalink
Change default link type to junction for Windows. See #11.
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-css committed Aug 30, 2019
1 parent 85dac84 commit dd91627
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ The plugin will run when you do:
- Deployment of individual functions (`sls deploy -f`)
- Spinning up a local sandbox with [serverless-offline](https://github.com/dherault/serverless-offline) (`sls offline [start]`)

## Settings

On Windows platforms only, the package will create [junction links]
(https://docs.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions) by default as these do not require
administrative privileges on older versions of Windows. You can set the `linkType` setting
to `dir` to create symbolic links instead. This setting is directly passed to the [fs.symlink](https://nodejs.org/docs/latest/api/fs.html#fs_fs_symlink_target_path_type_callback) function. It is ignored on non Windows platforms.

## Contributing

We welcome issue reports and pull requests!
Expand All @@ -62,4 +69,4 @@ the lint tool via `yarn lint` which will attempt to automatically issues like sp

## Copyright

Copyright [Butterwire Limited](https://www.butterwire.com) 2018
Copyright [Butterwire Limited](https://www.butterwire.com) 2018 - 2019
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const getNodeModulePaths = p => {
}

// Creates a symlink. Ignores if fails to create due to already existing.
async function link (target, f) {
async function link (target, f, type) {
await fs.ensureDir(path.dirname(f))
await fs.symlink(target, f, 'dir')
await fs.symlink(target, f, type)
.catch(e => {
if (e.code === 'EEXIST') {
return
Expand Down Expand Up @@ -43,6 +43,7 @@ class ServerlessMonoRepo {
const custom = this.serverless.service.custom || {}
this.settings = custom.serverlessMonoRepo || {}
this.settings.path = this.settings.path || this.serverless.config.servicePath
this.settings.linkType = 'junction'
}

async linkPackage (name, fromPath, toPath, created, resolved) {
Expand All @@ -61,7 +62,7 @@ class ServerlessMonoRepo {
const target = path.relative(path.join(toPath, path.dirname(name)), path.dirname(pkg))
if ((pkg.match(/node_modules/g) || []).length <= 1 && !created.has(name)) {
created.add(name)
await link(target, path.join(toPath, name))
await link(target, path.join(toPath, name), this.settings.linkType)
}

// Get dependencies
Expand Down

0 comments on commit dd91627

Please sign in to comment.