Allow schematics to create file with permissions

Open
#11,781 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
angular, typescript
Domain
cli

Research direction

Start at the @schematics/angular:library entry point and follow how it creates files before the NodePackageInstallTask runs. Use the executable Taskfile and the generated package.json workaround as the reproduction case. Done means a schematic can create or modify a file with executable permissions without relying on the self-destructing preinstall script.

Written by the indexing model from the issue text.

Description

area: @angular-devkit/schematics feature feature: insufficient votes
Bug Report or Feature Request (mark with an x)
- [ ] bug report -> please search issues before submitting
- [x] feature request
Versions

any

Desired functionality

I'm writing schematics to help colleagues scaffold applications and libraries following our internal guidelines. One part of our set-up is the use of a file called Taskfile to contain scripts instead of cramming complicated one-liners in yarn run-scripts. This file should be executable, but a schematic cannot create executable files. The result is a broken package because ./Taskfile: Permission denied.

I've got a simple workaround:

The schematic in question is based on @schematics/angular:library. It runs the NodePackageInstallTask at the end. This allows me to create a selfdestructing preinstall script in the newly scaffolded package.json:

{
  "//": "...",
  "scripts": {
    "preinstall": "chmod +x Taskfile && ex +g/preinstall/d -cwq package.json",
    "prepublish": "./Taskfile build",
    "test": "./Taskfile test"
  }
}

This works, but it feels like a hack to me. It would be cleaner if either

  • file permissions were respected, as the source file for the scaffold has correct permissions; or
  • the schematic could modify permissions
Dominant language
TypeScript
Stars
27k
Forks
11.8k
Avg merge
16h 35m
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from angular/angular-cli

All issues in angular/angular-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.