How to use the @jsii/spec.SPEC_FILE_NAME function in @jsii/spec

To help you get started, we’ve selected a few @jsii/spec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / jsii / packages / jsii-pacmak / lib / npm-modules.ts View on Github external
if (await fs.pathExists(npmIgnorePath)) {
    lines = (await fs.readFile(npmIgnorePath)).toString().split('\n');
  }

  // if this is a fresh .npmignore, we can be a bit more opinionated
  // otherwise, we add just add stuff that's critical
  if (lines.length === 0) {
    excludePattern('Exclude typescript source and config', '*.ts', 'tsconfig.json');
    includePattern('Include javascript files and typescript declarations', '*.js', '*.d.ts');
  }

  if (excludeOutdir) {
    excludePattern('Exclude jsii outdir', path.relative(packageDir, excludeOutdir));
  }

  includePattern('Include .jsii', spec.SPEC_FILE_NAME);

  if (modified) {
    await fs.writeFile(npmIgnorePath, `${lines.join('\n')}\n`);
    logging.info('Updated .npmignore');
  }

  function includePattern(comment: string, ...patterns: string[]) {
    excludePattern(comment, ...patterns.map(p => `!${p}`));
  }

  function excludePattern(comment: string, ...patterns: string[]) {
    let first = true;
    for (const pattern of patterns) {
      if (lines.includes(pattern)) {
        return; // already in .npmignore
      }
github aws / jsii / packages / jsii-pacmak / lib / targets / dotnet / dotnetgenerator.ts View on Github external
filegen.generateAssemblyInfoFile();
    filegen.generateProjectFile(this.typeresolver.namespaceDependencies);
    // Calling super.save() dumps the tarball in the format name@version.jsii.tgz.
    // This is not in sync with the Old .NET generator where the name is scope-name-version.tgz.
    // Hence we are saving the files ourselves here:
    const assm = this.assembly;
    const packageId: string = assm.targets!.dotnet!.packageId;
    if (!packageId) { throw new Error(`The module ${assm.name} does not have a dotnet.packageId setting`); }
    await fs.mkdirp(path.join(outdir, packageId));
    await fs.copyFile(tarball, path.join(outdir, packageId, tarballFileName));

    // Create an anchor file for the current model
    this.generateDependencyAnchorFile();

    // Copying the .jsii file
    await fs.copyFile(this.jsiiFilePath, path.join(outdir, packageId, spec.SPEC_FILE_NAME));

    // Saving the generated code.
    return this.code.save(outdir);
  }
github aws / jsii / packages / @jsii / kernel / lib / kernel.ts View on Github external
this._debug('look up already-loaded assembly', pkgname);
      const assm = this.assemblies[pkgname];

      return {
        assembly: assm.metadata.name,
        types: Object.keys(assm.metadata.types ?? {}).length,
      };
    }
    // untar the archive to a staging directory, read the jsii spec from it
    // and then move it to the node_modules directory of the kernel.
    const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-kernel-install-staging-'));
    try {
      tar.extract({ strict: true, file: req.tarball, cwd: staging, sync: true });

      // read .jsii metadata from the root of the package
      const jsiiMetadataFile = path.join(staging, 'package', spec.SPEC_FILE_NAME);
      if (!fs.pathExistsSync(jsiiMetadataFile)) {
        throw new Error(`Package tarball ${req.tarball} must have a file named ${spec.SPEC_FILE_NAME} at the root`);
      }
      const assmSpec = fs.readJsonSync(jsiiMetadataFile) as spec.Assembly;

      // "install" to "node_modules" directory
      fs.moveSync(path.join(staging, 'package'), packageDir);

      // load the module and capture it's closure
      const closure = this._execute(`require(String.raw\`${packageDir}\`)`, packageDir);
      const assm = new Assembly(assmSpec, closure);
      this._addAssembly(assm);

      return {
        assembly: assmSpec.name,
        types: Object.keys(assmSpec.types ?? {}).length,
github aws / jsii / packages / @jsii / kernel / lib / kernel.ts View on Github external
return {
        assembly: assm.metadata.name,
        types: Object.keys(assm.metadata.types ?? {}).length,
      };
    }
    // untar the archive to a staging directory, read the jsii spec from it
    // and then move it to the node_modules directory of the kernel.
    const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'jsii-kernel-install-staging-'));
    try {
      tar.extract({ strict: true, file: req.tarball, cwd: staging, sync: true });

      // read .jsii metadata from the root of the package
      const jsiiMetadataFile = path.join(staging, 'package', spec.SPEC_FILE_NAME);
      if (!fs.pathExistsSync(jsiiMetadataFile)) {
        throw new Error(`Package tarball ${req.tarball} must have a file named ${spec.SPEC_FILE_NAME} at the root`);
      }
      const assmSpec = fs.readJsonSync(jsiiMetadataFile) as spec.Assembly;

      // "install" to "node_modules" directory
      fs.moveSync(path.join(staging, 'package'), packageDir);

      // load the module and capture it's closure
      const closure = this._execute(`require(String.raw\`${packageDir}\`)`, packageDir);
      const assm = new Assembly(assmSpec, closure);
      this._addAssembly(assm);

      return {
        assembly: assmSpec.name,
        types: Object.keys(assmSpec.types ?? {}).length,
      };
    } finally {