cuelang.org/go@v0.10.1/mod/modfile/schema.cue (about)

     1  // Copyright 2023 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // This schema constrains a module.cue file. This form constrains module.cue files
    16  // outside of the main module. For the module.cue file in a main module, the schema
    17  // is less restrictive, because wherever #Semver is used, a less specific version may be
    18  // used instead, which will be rewritten to the canonical form by the cue command tooling.
    19  // To check against that form,
    20  
    21  // versions holds an element for each supported version
    22  // of the schema. The version key specifies that
    23  // the schema covers all versions from then until the
    24  // next version present in versions, or until the current CUE version,
    25  // whichever is earlier.
    26  versions: [string]: {
    27  	// #File represents the overarching module file schema.
    28  	#File!: {
    29  		// We always require the language version, as we use
    30  		// that to determine how to parse the file itself.
    31  		// Note that this schema is not used by [ParseLegacy]
    32  		// because legacy module.cue files did not support
    33  		// language.version field.
    34  		language!: version!: string
    35  	}
    36  
    37  	// #Strict can be unified with the top level schema to enforce the strict version
    38  	// of the schema required when publishing a module.
    39  	#Strict!: _
    40  }
    41  
    42  versions: "v0.8.0-alpha.0": {
    43  	// Define this version in terms of the later versions
    44  	// rather than the other way around, so that
    45  	// the latest version is clearest.
    46  	versions["v0.9.0-alpha.0"]
    47  
    48  	// The source field was added in v0.9.0, so "remove"
    49  	// it here by marking it as an error when used.
    50  	#File: source?: _errorSourceFieldRequiredVersion
    51  }
    52  
    53  versions: "v0.9.0-alpha.0": {
    54  	#File: {
    55  		// module indicates the module's path.
    56  		module?: #Module | ""
    57  
    58  		// version indicates the language version used by the code in this module
    59  		// - the minimum version of CUE required to evaluate the code in this
    60  		// module. When a later version of CUE is evaluating code in this module,
    61  		// this will be used to choose version-specific behavior. If an earlier
    62  		// version of CUE is used, an error will be given.
    63  		language?: version?: #Semver
    64  
    65  		// source holds information about the source of the files within the
    66  		// module. This field is mandatory at publish time.
    67  		source?: #Source
    68  
    69  		// description describes the purpose of this module.
    70  		description?: string
    71  
    72  		// deps holds dependency information for modules, keyed by module path.
    73  		deps?: [#Module]: #Dep
    74  
    75  		// custom holds arbitrary data intended for use by third-party tools.
    76  		// Each field at the top level represents a tooling namespace,
    77  		// conventionally a module or domain name. Data migrated from legacy
    78  		// module.cue files is placed in the "legacy" namespace.
    79  		custom?: [#Module | "legacy"]: [_]: _
    80  
    81  		#Dep: {
    82  			// v indicates the minimum required version of the module. This can
    83  			// be null if the version is unknown and the module entry is only
    84  			// present to be replaced.
    85  			v!: #Semver | null
    86  
    87  			// default indicates this module is used as a default in case more
    88  			// than one major version is specified for the same module path.
    89  			// Imports must specify the exact major version for a module path if
    90  			// there is more than one major version for that path and default is
    91  			// not set for exactly one of them.
    92  			default?: bool
    93  		}
    94  
    95  		// #Module constrains a module path. The major version indicator is
    96  		// optional, but should always be present in a normalized module.cue
    97  		// file.
    98  		#Module: string
    99  
   100  		// #Semver constrains a semantic version.
   101  		#Semver: =~"."
   102  	}
   103  
   104  	// #Strict can be unified with the top level schema to enforce the strict version
   105  	// of the schema required by the registry.
   106  	#Strict: #File & {
   107  		// This regular expression is taken from https://semver.org/spec/v2.0.0.html
   108  		#Semver: =~#"^v(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"#
   109  
   110  		#Module: =~#"^[^@]+(@v(0|[1-9]\d*))$"#
   111  
   112  		// The module declaration is required.
   113  		module!: #Module
   114  
   115  		// No null versions, because no replacements yet.
   116  		#Dep: v!: #Semver
   117  	}
   118  
   119  	// #Source describes a source of truth for a module's content.
   120  	#Source: {
   121  		// kind specifies the kind of source.
   122  		//
   123  		// The special value "self" signifies a module is stand-alone, associated
   124  		// with no particular source. The module's file list is determined from
   125  		// the contents of the directory (and its subdirectories) that contains
   126  		// the cue.mod directory.
   127  		//
   128  		// See https://cuelang.org/docs/reference/modules/#determining-zip-file-contents
   129  		// for details on all the possible values for kind, and how they relate
   130  		// to determining the list of files in a module.
   131  		kind!: "self" | "git"
   132  
   133  		// TODO support for other VCSs:
   134  		// kind!: "self" | "git" | "bzr" | "hg" | "svn"
   135  	}
   136  }
   137  
   138  // The //error comments are specially recognized by the parsing
   139  // code so we can avoid opaque conflict errors.
   140  // TODO use error function when that's available.
   141  //
   142  // Note: we're using 1&2 rather than _|_ because
   143  // use of _|_ causes the source location of the errors
   144  // to be lost. See https://github.com/cue-lang/cue/issues/2319.
   145  
   146  //error: source field is not allowed at this language version; need at least v0.9.0-alpha.0
   147  let _errorSourceFieldRequiredVersion = 1 & 2