Skip to content

Commit

Permalink
Merge branch 'main' into tomknickman/turbo-531-globally-installed-tur…
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman committed Nov 30, 2022
2 parents 9b4ef7c + fb5229f commit 672ad7b
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist/

/examples/

packages/eslint-plugin-turbo/__tests__/fixtures
packages/create-turbo/templates
packages/turbo-tracing-next-plugin/test/with-mongodb-mongoose
crates/*/tests/**
Expand Down
4 changes: 4 additions & 0 deletions cli/integration_tests/single_package/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Check
{
"task": "build",
"hash": "7bf32e1dedb04a5d",
"cacheState": {
"local": false,
"remote": false
},
"command": "echo 'building' \u003e foo",
"outputs": [
"foo"
Expand Down
8 changes: 8 additions & 0 deletions cli/integration_tests/single_package_deps/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Check
{
"task": "build",
"hash": "8fc80cfff3b64237",
"cacheState": {
"local": false,
"remote": false
},
"command": "echo 'building' \u003e foo",
"outputs": [
"foo"
Expand All @@ -47,6 +51,10 @@ Check
{
"task": "test",
"hash": "c71366ccd6a86465",
"cacheState": {
"local": false,
"remote": false
},
"command": "[[ ( -f foo ) \u0026\u0026 $(cat foo) == 'building' ]]",
"outputs": null,
"excludedOutputs": null,
Expand Down
4 changes: 4 additions & 0 deletions cli/integration_tests/single_package_no_config/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Check
{
"task": "build",
"hash": "c7223f212c321d3b",
"cacheState": {
"local": false,
"remote": false
},
"command": "echo 'building'",
"outputs": null,
"excludedOutputs": null,
Expand Down
33 changes: 18 additions & 15 deletions cli/internal/run/dry_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,15 @@ type hashedTask struct {
}

type hashedSinglePackageTask struct {
Task string `json:"task"`
Hash string `json:"hash"`
Command string `json:"command"`
Outputs []string `json:"outputs"`
ExcludedOutputs []string `json:"excludedOutputs"`
LogFile string `json:"logFile"`
Dependencies []string `json:"dependencies"`
Dependents []string `json:"dependents"`
Task string `json:"task"`
Hash string `json:"hash"`
CacheState cache.ItemStatus `json:"cacheState"`
Command string `json:"command"`
Outputs []string `json:"outputs"`
ExcludedOutputs []string `json:"excludedOutputs"`
LogFile string `json:"logFile"`
Dependencies []string `json:"dependencies"`
Dependents []string `json:"dependents"`
}

func (ht *hashedTask) toSinglePackageTask() hashedSinglePackageTask {
Expand All @@ -299,12 +300,14 @@ func (ht *hashedTask) toSinglePackageTask() hashedSinglePackageTask {
dependents[i] = util.StripPackageName(dependent)
}
return hashedSinglePackageTask{
Task: util.RootTaskTaskName(ht.TaskID),
Hash: ht.Hash,
Command: ht.Command,
Outputs: ht.Outputs,
LogFile: ht.LogFile,
Dependencies: dependencies,
Dependents: dependents,
Task: util.RootTaskTaskName(ht.TaskID),
Hash: ht.Hash,
CacheState: ht.CacheState,
Command: ht.Command,
Outputs: ht.Outputs,
ExcludedOutputs: ht.ExcludedOutputs,
LogFile: ht.LogFile,
Dependencies: dependencies,
Dependents: dependents,
}
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format:prettier": "prettier -w .",
"format:rs": "cargo fmt --all",
"format:toml": "taplo format",
"lint": "eslint . --ext js,jsx,ts,tsx -c ./.eslintrc.js",
"lint": "eslint . --ext js,jsx,ts,tsx",
"turbo": "cd cli && make turbo && cd .. && node turbow.js",
"docs": "pnpm -- turbo run dev --filter=docs --no-cache",
"run-example": "./scripts/run-example.sh"
Expand All @@ -33,10 +33,11 @@
"typescript": "^4.8.4"
},
"lint-staged": {
"*.@(js|ts)": [
"eslint --quiet --fix"
"*.{js,jsx,ts,tsx}": [
"pnpm run lint --quiet --fix --",
"prettier --write"
],
"*.{ts,tsx,md,mdx,js,jsx,mjs,yml,yaml,css}": [
"*.{md,mdx,mjs,yml,yaml,css}": [
"prettier --write"
],
"*.go": [
Expand Down
111 changes: 111 additions & 0 deletions packages/eslint-plugin-turbo/__tests__/cwd.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import fs from "fs";
import path from "path";
import JSON5 from "json5";
import { execSync } from "child_process";

describe("eslint settings check", () => {
beforeAll(() => {
const cwd = path.join(__dirname, "fixtures", "workspace");
execSync(`npm install`, { cwd });
});

afterAll(() => {
const nodeModulesDir = path.join(
__dirname,
"fixtures",
"workspace",
"node_modules"
);
fs.rmSync(nodeModulesDir, { force: true, recursive: true });
});

it("does the right thing for peers", () => {
const cwd = path.join(__dirname, "fixtures", "workspace");
const configString = execSync(`eslint --print-config peer.js`, {
cwd,
encoding: "utf8",
});
const configJson = JSON.parse(configString);

expect(configJson.settings).toEqual({
turbo: { envVars: ["CI", "UNORDERED"] },
});
});

it("does the right thing for child dirs", () => {
const cwd = path.join(__dirname, "fixtures", "workspace", "child");
const configString = execSync(`eslint --print-config child.js`, {
cwd,
encoding: "utf8",
});
const configJson = JSON.parse(configString);

expect(configJson.settings).toEqual({
turbo: { envVars: ["CI", "UNORDERED"] },
});
});
});

describe("eslint cache is busted", () => {
let turboJsonPath: string;
let originalString: string;

beforeAll(() => {
const cwd = path.join(__dirname, "fixtures", "workspace");
execSync(`npm install`, { cwd });

turboJsonPath = path.join(__dirname, "fixtures", "workspace", "turbo.json");
originalString = fs.readFileSync(turboJsonPath, { encoding: "utf8" });
});

afterEach(() => {
fs.writeFileSync(turboJsonPath, originalString);
});

afterAll(() => {
fs.writeFileSync(turboJsonPath, originalString);

const nodeModulesDir = path.join(
__dirname,
"fixtures",
"workspace",
"node_modules"
);
fs.rmSync(nodeModulesDir, { force: true, recursive: true });
});

it("catches a lint error after changing config", () => {
expect.assertions(2);

// ensure that we populate the cache with a failure.
const cwd = path.join(__dirname, "fixtures", "workspace", "child");
try {
execSync(`eslint --format=json child.js`, { cwd, encoding: "utf8" });
} catch (error: any) {
const outputJson = JSON.parse(error.stdout);
expect(outputJson).toMatchObject([
{
messages: [
{
message:
"$NONEXISTENT is not listed as a dependency in turbo.json",
},
],
},
]);
}

// change the configuration
const turboJson = JSON5.parse(originalString);
turboJson.globalEnv = ["CI", "NONEXISTENT"];
fs.writeFileSync(turboJsonPath, JSON.stringify(turboJson, null, 2));

// test that we invalidated the eslint cache
const output = execSync(`eslint --format=json child.js`, {
cwd,
encoding: "utf8",
});
const outputJson = JSON.parse(output);
expect(outputJson).toMatchObject([{ errorCount: 0 }]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["plugin:turbo/recommended"],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
process.env.NONEXISTENT
process.env.CI
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"eslint-plugin-turbo": "../../.."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.CI
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://turbo.build/schema.json",
"globalEnv": ["UNORDERED", "CI"],
"pipeline": {
"build": {
// A workspace's `build` task depends on that workspace's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import findTurboConfig from "../../lib/utils/findTurboConfig";

describe("findTurboConfig", () => {
it("it parses valid turbo.json file", () => {
const cwd = path.resolve(__dirname, "./fixtures/workspace");
const cwd = path.join(__dirname, "..", "fixtures", "workspace");
expect(findTurboConfig({ cwd })).toEqual({
$schema: "https://turbo.build/schema.json",
globalEnv: ["UNORDERED", "CI"],
pipeline: {
build: {
dependsOn: ["^build"],
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-turbo/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testPathIgnorePatterns: [".+/fixtures/.+"],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["<rootDir>/node_modules", "<rootDir>/dist"],
preset: "ts-jest",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-turbo/lib/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const envVars = getEnvVarDependencies({
});
const settings = {
turbo: {
envVars: envVars ? [...envVars] : [],
envVars: envVars ? [...envVars].sort() : [],
},
};

Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$schema": "./docs/public/schema.json",
"pipeline": {
"eslint-plugin-turbo#test": {
"dependsOn": ["build"]
},
"test": {
"outputs": ["coverage/**/*"],
"dependsOn": ["^build"]
Expand Down

0 comments on commit 672ad7b

Please sign in to comment.