Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readonly attribute on environment scipt file #1031

Closed
lorond opened this issue Feb 1, 2019 · 10 comments · Fixed by #1118

Comments

@lorond
Copy link
Contributor

commented Feb 1, 2019

  • Library Version:
    aurelia-cli v1.0.0-beta.12

  • Operating System:
    Windows 10

  • Node Version:
    10.15.0

  • NPM Version:
    6.4.1

  • Browser:
    not applicable

  • Language:
    all

  • Loader/bundler:
    Webpack (didn't tested other)

Current behavior:
If target environment.[tj]s file is readonly, build fails when trying to copy corresponding file from aurelia_project\environments.

  • What is the expected behavior?
    As file created by aurelia on each build, readonly attribute should not fail entire build process.

  • What is the motivation / use case for changing the behavior?
    Team Foundation System with Server Repositories places readonly attribute on files that is not checked out. File environment.[tj]s is not exist on first build and copied with all attributes of source file, including readonly attribute as environment configuration files are rarely being edited and usually not checked out. Each subsequent build fails until either file or attribute removed. However, in this case source file copied again with all attributes. So it required to do manual cleanup before each build.

@3cp

This comment has been minimized.

Copy link
Member

commented Feb 1, 2019

Some windows user reported this issue before, but didn’t know it is from TFS.

Thanks for clarifying.

@avrahamcool

This comment has been minimized.

Copy link
Contributor

commented Feb 1, 2019

EDIT:
I now see you already know the cause and how to fix this.
(but i'll leave my initial response for others who might benefit)

ORIGINAL:
I also had the same problem back when I used TFS.
I altered the transpile and copy-files tasks - so they remove the readonly flag on the target file.

keep in mind that the cli generated tasks have changed since then - so you need to carefully change yours accordingly.
also - this need to be fixed in the ts versions as well.

first: install gulp-chmod' (using npm or yarn)

transpile.js

import gulp from 'gulp';
import changedInPlace from 'gulp-changed-in-place';
import plumber from 'gulp-plumber';
import babel from 'gulp-babel';
import sourcemaps from 'gulp-sourcemaps';
import notify from 'gulp-notify';
import rename from 'gulp-rename';
import project from '../aurelia.json';
import {CLIOptions, build} from 'aurelia-cli';
import chmod from 'gulp-chmod'; //<-- added

function configureEnvironment() {
  let env = CLIOptions.getEnvironment();

  return gulp.src(`aurelia_project/environments/${env}.js`)
    .pipe(changedInPlace({firstPass: true}))
    .pipe(rename('environment.js'))
	.pipe(chmod(666)) //<-- added
    .pipe(gulp.dest(project.paths.root));
}

function buildJavaScript() {
  return gulp.src(project.transpiler.source)
    .pipe(plumber({errorHandler: notify.onError('Error: <%= error.message %>')}))
    .pipe(changedInPlace({firstPass: true}))
    .pipe(sourcemaps.init())
    .pipe(babel(project.transpiler.options))
    .pipe(build.bundle());
}

export default gulp.series(
  configureEnvironment,
  buildJavaScript
);

copy-files.js

import gulp from 'gulp';
import path from 'path';
import minimatch from 'minimatch';
import changedInPlace from 'gulp-changed-in-place';
import project from '../aurelia.json';
import chmod from 'gulp-chmod'; //<-- added

export default function copyFiles(done)
{
	if (typeof project.build.copyFiles !== 'object')
	{
		done();
		return;
	}

	const instruction = getNormalizedInstruction();
	const files = Object.keys(instruction);

	return gulp.src(files)
		.pipe(changedInPlace({ firstPass: true }))
		.pipe(chmod(666))//<-- added
		.pipe(gulp.dest(x =>
		{
			const filePath = prepareFilePath(x.path);
			const key = files.find(f => minimatch(filePath, f));
			return instruction[key];
		}));
}

function getNormalizedInstruction()
{
	const files = project.build.copyFiles;
	let normalizedInstruction = {};

	for (let key in files)
	{
		normalizedInstruction[path.posix.normalize(key)] = files[key];
	}

	return normalizedInstruction;
}

function prepareFilePath(filePath)
{
	let preparedPath = filePath.replace(process.cwd(), '').substring(1);

	//if we are running on windows we have to fix the path
	if (/^win/.test(process.platform))
	{
		preparedPath = preparedPath.replace(/\\/g, '/');
	}

	return preparedPath;
}
@lorond

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

@avrahamcool it's enought just to add 0o200 - own write mode

@lorond

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2019

@avrahamcool also gulp-chmod would change source file attributes, isn't it? It could be not desired.

@3cp

This comment has been minimized.

Copy link
Member

commented Feb 6, 2019

I don't know TFS, is there an way to make sure the source file is not read-only?

https://stackoverflow.com/questions/17970762/all-project-files-get-read-only-attribute-after-download-from-tfs-2010

@avrahamcool

This comment has been minimized.

Copy link
Contributor

commented Feb 6, 2019

even if you can.. it's not something you want to do.
TFS takes control over your files, (editing in VisualStudio makes an implicit check-out action that clear the readonly flag)

@3cp

This comment has been minimized.

Copy link
Member

commented Feb 6, 2019

Sounds like everyone should switch to git...

@avrahamcool

This comment has been minimized.

Copy link
Contributor

commented Feb 6, 2019

in organizations.. this is not always open for you to deiced..

we are making it sound like it's a big issue.. clearing the readonly file while creating the environment file is pretty simple.

@3cp

This comment has been minimized.

Copy link
Member

commented Feb 6, 2019

There is other way for cli to not copy environment file, but it's breaking change.

In my own project, I didn't have an environment file, I use gulp-preprocess to conditionally modify source code, before sending the file to gulp-babel.

  // @if isProduction
  aurelia.use.developmentLogging('warn');
  // @endif
  // @if !isProduction
  aurelia.use.developmentLogging('info');
  // @endif

  // @if isTest
  aurelia.use.plugin('aurelia-testing');
  // @endif
@lorond

This comment has been minimized.

Copy link
Contributor Author

commented Feb 7, 2019

@huochunpeng environment file could be the only file processed in the same manner (e.g. mentioned gulp-preprocess or similar webpack loader) and this will not be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.