New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sprucelabs/babel-plugin-schema

Package Overview
Dependencies
Maintainers
3
Versions
232
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sprucelabs/babel-plugin-schema - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0

build/__tests__/files/import-test.ts

2

build/__tests__/behavioral/SchemaBuildsAndMapsPaths.test.d.ts

@@ -6,2 +6,4 @@ import AbstractSpruceTest from '@sprucelabs/test';

protected static buildsSchemaWithoutErrorWithoutLocalHashSpruce(): Promise<void>;
private static copyAndMap;
protected static testVariousMatches(): Promise<void>;
private static fieldFactoryFilepath;

@@ -8,0 +10,0 @@ protected static buildsSchemaAndUsesTheLocalHashSpruceVersionOfFiles(): Promise<void>;

@@ -33,2 +33,3 @@ "use strict";

const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const test_1 = __importStar(require("@sprucelabs/test"));

@@ -50,3 +51,3 @@ const fs_extra_1 = __importDefault(require("fs-extra"));

test_1.assert.doesInclude(contents, '#spruce');
index_1.copyAndMap({ cwd, destination: cwd });
this.copyAndMap(cwd);
const afterMapContents = fs_extra_1.default.readFileSync(fieldFactoryFile).toString();

@@ -57,2 +58,37 @@ test_1.assert.doesNotInclude(afterMapContents, cwd);

}
static copyAndMap(cwd) {
index_1.copy({ cwd, destination: cwd });
index_1.resolveHashSpruceAliases(cwd);
}
static async testVariousMatches() {
const cwd = await this.setupNewPackage();
const importFileTarget = this.resolvePath('src', '__tests__', 'files', 'import-test.ts');
const importFileContents = fs_extra_1.default.readFileSync(importFileTarget);
const destination = this.resolvePath(cwd, 'src', 'test-import.d.ts');
fs_extra_1.default.ensureDirSync(path_1.default.dirname(destination));
fs_extra_1.default.writeFileSync(destination, importFileContents);
this.copyAndMap(cwd);
const updatedContents = fs_extra_1.default.readFileSync(destination).toString();
test_1.assert.isEqual(updatedContents.trim(), `/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
//@ts-ignore
import skill from "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
//@ts-ignore
import skill2 from "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
import "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
require("./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types")
require("./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types")
const leaveThis = '#spruce/schemas/fields/fields.types'
const doNotTouch = '#spruce/schemas/fields/fields.types'
console.log(leaveThis, doNotTouch)
function leaveAsIs(str: string) {
console.log(str)
}
leaveAsIs('#spruce/schemas/fields/fields.types')`);
}
static fieldFactoryFilepath(cwd) {

@@ -67,3 +103,3 @@ return this.resolvePath(cwd, 'node_modules/@sprucelabs/schema', 'build/factories/FieldFactory.js');

await this.copyDir(sourceHashSpruce, destinationHashSpruce);
index_1.copyAndMap({ cwd, destination: cwd });
this.copyAndMap(cwd);
const fieldFactoryFile = this.fieldFactoryFilepath(cwd);

@@ -147,2 +183,5 @@ const afterMapContents = fs_extra_1.default.readFileSync(fieldFactoryFile).toString();

test_1.test()
], SchemaBuildsAndMapsPathsTest, "testVariousMatches", null);
__decorate([
test_1.test()
], SchemaBuildsAndMapsPathsTest, "buildsSchemaAndUsesTheLocalHashSpruceVersionOfFiles", null);

@@ -149,0 +188,0 @@ __decorate([

7

build/__tests__/empty_skill/package.json

@@ -19,6 +19,7 @@ {

"health.local": "yarn run boot.local --health",
"build": "yarn build.babel",
"build": "yarn build.babel && yarn build.resolve-paths",
"build.types": "tsc --emitDeclarationOnly",
"build.babel": "babel src --out-dir build --extensions '.ts, .tsx' --source-maps --copy-files",
"build.watch": "babel src --out-dir build --extensions '.ts, .tsx' --source-maps --copy-files --watch",
"build.resolve-paths": "resolve-path-aliases build && resolve-path-aliases node_modules/@sprucelabs/schema/build",
"clean": "rm -rf build/",

@@ -42,3 +43,3 @@ "clean.all": "rm -rf build/ && rm -rf node_modules/"

"@babel/preset-typescript": "^7.10.4",
"@sprucelabs/babel-plugin-schema": "^1.1.121",
"@sprucelabs/babel-plugin-schema": "^1.2.1",
"@types/node": "^14.6.3",

@@ -53,2 +54,2 @@ "babel-plugin-module-resolver": "^4.0.0",

}
}
}

@@ -5,4 +5,4 @@ export interface PluginOptions {

}
export declare function copyAndMap(options: PluginOptions): void;
export declare function copy(options: PluginOptions): void;
export declare function resolveHashSpruceAliases(destination: string): void;
export default function (_: any, options: PluginOptions): {};

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveHashSpruceAliases = exports.copyAndMap = void 0;
exports.resolveHashSpruceAliases = exports.copy = void 0;
const fs_1 = __importDefault(require("fs"));

@@ -19,9 +19,8 @@ const path_1 = __importDefault(require("path"));

}
function copyAndMap(options) {
function copy(options) {
assert(options.cwd, "You must pass options.cwd. This is where I'll look for the schema module (root of workspace if in monorepo)");
assert(options.destination, 'You need to pass a options.destination (sub project if mono repo)');
const destination = ensureDirsAndResolveDestination(options);
resolveHashSpruceAliases(destination);
ensureDirsAndResolveDestination(options);
}
exports.copyAndMap = copyAndMap;
exports.copy = copy;
function resolveHashSpruceAliases(destination) {

@@ -36,5 +35,5 @@ let { outResolver, srcResolver } = buildResolvers(destination);

let found = false;
contents = `${contents}`.replace(/['"]#spruce\/(.*?)['"]/gi, (match) => {
contents = `${contents}`.replace(/(from |import |require\()['"](#spruce\/(.*?))['"]/gi, (_, requireOrImport, match) => {
found = true;
const search = match.replace(/["']/g, '');
const search = match;
let resolved;

@@ -48,6 +47,6 @@ if (outResolver) {

if (!resolved) {
throw new Error(`Could not map ${search}.`);
throw new Error(`Could not map ${search} in ${file}.`);
}
const relative = path_1.default.relative(path_1.default.dirname(file), resolved);
return `"./${relative}"`;
return `${requireOrImport}"./${relative}"`;
});

@@ -103,3 +102,3 @@ if (found) {

function default_1(_, options) {
copyAndMap(options);
copy(options);
return {};

@@ -106,0 +105,0 @@ }

@@ -0,1 +1,8 @@

# [2.0.0](https://github.com/sprucelabsai/babel-plugin-schema/compare/v1.2.1...v2.0.0) (2020-09-04)
### Breaking Changes
* better matching and mapping happens seperate from copy of schema ([0845d89](https://github.com/sprucelabsai/babel-plugin-schema/commit/0845d89))
## [1.2.1](https://github.com/sprucelabsai/babel-plugin-schema/compare/v1.2.0...v1.2.1) (2020-09-04)

@@ -2,0 +9,0 @@

{
"name": "@sprucelabs/babel-plugin-schema",
"version": "1.2.1",
"version": "2.0.0",
"description": "Builds @sprucelabs/schema and generates static paths to #spruce directories.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

import { exec } from 'child_process'
import os from 'os'
import pathUtil from 'path'
import AbstractSpruceTest, { test, assert } from '@sprucelabs/test'
import fsUtil from 'fs-extra'
import rimraf from 'rimraf'
import { copyAndMap } from '../../index'
import { copy, resolveHashSpruceAliases } from '../../index'

@@ -27,3 +28,3 @@ export default class SchemaBuildsAndMapsPathsTest extends AbstractSpruceTest {

copyAndMap({ cwd, destination: cwd })
this.copyAndMap(cwd)

@@ -40,2 +41,52 @@ const afterMapContents = fsUtil.readFileSync(fieldFactoryFile).toString()

private static copyAndMap(cwd: string) {
copy({ cwd, destination: cwd })
resolveHashSpruceAliases(cwd)
}
@test()
protected static async testVariousMatches() {
const cwd = await this.setupNewPackage()
const importFileTarget = this.resolvePath(
'src',
'__tests__',
'files',
'import-test.ts'
)
const importFileContents = fsUtil.readFileSync(importFileTarget)
const destination = this.resolvePath(cwd, 'src', 'test-import.d.ts')
fsUtil.ensureDirSync(pathUtil.dirname(destination))
fsUtil.writeFileSync(destination, importFileContents)
this.copyAndMap(cwd)
const updatedContents = fsUtil.readFileSync(destination).toString()
assert.isEqual(
updatedContents.trim(),
`/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
//@ts-ignore
import skill from "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
//@ts-ignore
import skill2 from "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
import "./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types"
require("./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types")
require("./../node_modules/@sprucelabs/schema/build/.spruce/schemas/fields/fields.types")
const leaveThis = '#spruce/schemas/fields/fields.types'
const doNotTouch = '#spruce/schemas/fields/fields.types'
console.log(leaveThis, doNotTouch)
function leaveAsIs(str: string) {
console.log(str)
}
leaveAsIs('#spruce/schemas/fields/fields.types')`
)
}
private static fieldFactoryFilepath(cwd: string) {

@@ -66,3 +117,3 @@ return this.resolvePath(

copyAndMap({ cwd, destination: cwd })
this.copyAndMap(cwd)

@@ -92,2 +143,3 @@ const fieldFactoryFile = this.fieldFactoryFilepath(cwd)

.replace('{{schema-plugin}}', buildIndex)
fsUtil.writeFileSync(babelFile, babelContents)

@@ -94,0 +146,0 @@

@@ -19,6 +19,7 @@ {

"health.local": "yarn run boot.local --health",
"build": "yarn build.babel",
"build": "yarn build.babel && yarn build.resolve-paths",
"build.types": "tsc --emitDeclarationOnly",
"build.babel": "babel src --out-dir build --extensions '.ts, .tsx' --source-maps --copy-files",
"build.watch": "babel src --out-dir build --extensions '.ts, .tsx' --source-maps --copy-files --watch",
"build.resolve-paths": "resolve-path-aliases build && resolve-path-aliases node_modules/@sprucelabs/schema/build",
"clean": "rm -rf build/",

@@ -42,3 +43,3 @@ "clean.all": "rm -rf build/ && rm -rf node_modules/"

"@babel/preset-typescript": "^7.10.4",
"@sprucelabs/babel-plugin-schema": "^1.1.121",
"@sprucelabs/babel-plugin-schema": "^1.2.1",
"@types/node": "^14.6.3",

@@ -53,2 +54,2 @@ "babel-plugin-module-resolver": "^4.0.0",

}
}
}

@@ -24,3 +24,3 @@ import fs from 'fs'

export function copyAndMap(options: PluginOptions) {
export function copy(options: PluginOptions) {
assert(

@@ -35,5 +35,3 @@ options.cwd,

const destination = ensureDirsAndResolveDestination(options)
resolveHashSpruceAliases(destination)
ensureDirsAndResolveDestination(options)
}

@@ -53,23 +51,26 @@

contents = `${contents}`.replace(/['"]#spruce\/(.*?)['"]/gi, (match) => {
found = true
const search = match.replace(/["']/g, '')
let resolved: string | undefined
contents = `${contents}`.replace(
/(from |import |require\()['"](#spruce\/(.*?))['"]/gi,
(_, requireOrImport, match) => {
found = true
const search = match
let resolved: string | undefined
if (outResolver) {
resolved = outResolver(search, undefined, undefined, ['.ts', '.js'])
}
if (outResolver) {
resolved = outResolver(search, undefined, undefined, ['.ts', '.js'])
}
if (!resolved) {
resolved = srcResolver(search, undefined, undefined, ['.ts', '.js'])
}
if (!resolved) {
resolved = srcResolver(search, undefined, undefined, ['.ts', '.js'])
}
if (!resolved) {
throw new Error(`Could not map ${search}.`)
if (!resolved) {
throw new Error(`Could not map ${search} in ${file}.`)
}
const relative = pathUtil.relative(pathUtil.dirname(file), resolved)
return `${requireOrImport}"./${relative}"`
}
)
const relative = pathUtil.relative(pathUtil.dirname(file), resolved)
return `"./${relative}"`
})
if (found) {

@@ -170,4 +171,4 @@ fs.writeFileSync(file, contents)

export default function (_: any, options: PluginOptions) {
copyAndMap(options)
copy(options)
return {}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc