tools/isobuild/builder.js
// If `file` is used then it will be added to the builder's WatchSet.
If `file` is used then it will be added to the builder's WatchSet.
If ` file ` is used then it will be added to the builder ' s WatchSet .
write(relPath, {data, file, hash, sanitize, executable, symlink}) {
    if (relPath.slice(-1) === files.pathSep) {
      relPath = relPath.slice(0, -1);
    }
    if (sanitize) {
      relPath = this._sanitize(relPath);
    }
    let getData = null;
    if (data) {
      if (! (data instanceof Buffer)) {
        throw new Error("data must be a Buffer");
      }
      if (file) {
        throw new Error("May only pass one of data and file, not both");
      }
      getData = () => data;
    } else if (file) {
      getData = () => readAndWatchFile(this.watchSet, files.pathResolve(file));
    } else if (! symlink) {
      throw new Error('Builder can not write without either data or a file path or a symlink path: ' + relPath);
    }
    this._ensureDirectory(files.pathDirname(relPath));
    const absPath = files.pathJoin(this.buildPath, relPath);
    if (symlink) {
      symlinkWithOverwrite(symlink, absPath);
    } else {
      hash = hash || sha1(getData());
      if (this.previousWrittenHashes[relPath] !== hash) {
        atomicallyRewriteFile(absPath, getData(), {
          mode: executable ? 0o555 : 0o444
        });
      }
      this.writtenHashes[relPath] = hash;
    }
    this.usedAsFile[relPath] = true;
    return relPath;
  }
write ( relPath , { data , file , hash , sanitize , executable , symlink } ) { if ( relPath . slice ( - 1 ) === files . pathSep ) { relPath = relPath . slice ( 0 , - 1 ) ; } if ( sanitize ) { relPath = this . _sanitize ( relPath ) ; } let getData = null ; if ( data ) { if ( ! ( data instanceof Buffer ) ) { throw new Error ( "data must be a Buffer" ) ; } if ( file ) { throw new Error ( "May only pass one of data and file, not both" ) ; } getData = ( ) => data ; } else if ( file ) { getData = ( ) => readAndWatchFile ( this . watchSet , files . pathResolve ( file ) ) ; } else if ( ! symlink ) { throw new Error ( 'Builder can not write without either data or a file path or a symlink path: ' + relPath ) ; } this . _ensureDirectory ( files . pathDirname ( relPath ) ) ; const absPath = files . pathJoin ( this . buildPath , relPath ) ; if ( symlink ) { symlinkWithOverwrite ( symlink , absPath ) ; } else { hash = hash || sha1 ( getData ( ) ) ; if ( this . previousWrittenHashes [ relPath ] !== hash ) { atomicallyRewriteFile ( absPath , getData ( ) , { mode : executable ? 0o555 : 0o444 } ) ; } this . writtenHashes [ relPath ] = hash ; } this . usedAsFile [ relPath ] = true ; return relPath ; }
If `file` is used then it will be added to the builder's WatchSet.
If ` file ` is used then it will be added to the builder ' s WatchSet .
// Ensure no trailing slash // In sanitize mode, ensure path does not contain segments like // '..', does not contain forbidden characters, and is unique. // postpone reading the file into memory // Builder is used to create build products, which should be read-only; // users shouldn't be manually editing automatically generated files and // expecting the results to "stick".